1 回答
TA贡献1842条经验 获得超12个赞
在您的活动中使用以下代码:
我创建StringBuffer appNameAndPermissions = new StringBuffer();以附加所有应用程序和权限信息。
它工作正常。我已经测试过了。如果您有任何问题,请告诉我。
StringBuffer appNameAndPermissions = new StringBuffer();
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
try {
PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
appNameAndPermissions.append(packageInfo.packageName+"*******:\n");
//Get Permissions
String[] requestedPermissions = packageInfo.requestedPermissions;
if(requestedPermissions != null) {
for (int i = 0; i < requestedPermissions.length; i++) {
Log.d("test", requestedPermissions[i]);
appNameAndPermissions.append(requestedPermissions[i]+"\n");
}
appNameAndPermissions.append("\n");
} catch (NameNotFoundException e) {
e.printStackTrace();
}
在您的 AndroidManifest.xml 文件中使用以下权限:
<uses-permission android:name="android.permission.GET_TASKS"/>
来源和更多答案在这里
添加回答
举报