Android 仅限应用列表权限

Android app listing permissions only

我正在开发一个 android 应用程序,它将显示安装在移动设备 phone 中的所有应用程序,当单击特定应用程序时,它应该只显示该应用程序的权限。我使用包管理器来获取已安装 apk 的所有详细信息。 部分代码在这里:

    PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> applist = packageManager.getInstalledPackages(0);
    Iterator<PackageInfo> it = applist.iterator();
    while (it.hasNext()) {
        PackageInfo pk = (PackageInfo) it.next();
        PackageInfo pk1 = (PackageInfo) it.next();



        if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            // Log.v("System app using internet = ",""+ pk.applicationInfo.loadLabel(packageManager));
            String p = pk.applicationInfo.loadLabel(packageManager).toString();

            if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.CAMERA, pk.packageName))
                //results.add("" +"\n"+pk.applicationInfo.loadLabel(packageManager));





            {
                //Drawable appicon = getPackageManager().getApplicationIcon("com.google.maps");
                results.add("" + "\n" + pk.applicationInfo.loadLabel(packageManager));
            }
            if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, pk.packageName))
                results1.add("" +"\n"+pk1.applicationInfo.loadLabel(packageManager));
        }

    }

在列出应用程序时,我应该得到图标后跟应用程序名称。

Icon and application name example 我应该如何修改此代码以便获得所需的输出。

Example app

Official document

核心代码:

packageInfo.requestedPermissions?.forEach { permission -> ... }

更多链接

https://developer.android.com/reference/android/Manifest.permission.html

https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/res/AndroidManifest.xml

http://androidpermissions.com/