1

我目前正在尝试遍历列表以从手机上所有已安装的应用程序中查找特定权限,有人可以告诉我遍历列表的正确方法吗?

public void getPermissions(Context context) {
    PackageManager packageManager = context.getPackageManager();
    final List<PackageInfo> apps = context.getPackageManager()
        .getInstalledPackages(PackageManager.GET_PERMISSIONS);

    for (PackageInfo pi : apps) {
        String[] permissions = pi.requestedPermissions;
        if (permissions != null) {
            for (String permission : permissions) {
                Log.d("TAG", permission);
                            if (permission.equals("android.permission.INTERNET")) {

                                String appname=pi.applicationInfo.loadLabel(packageManager).toString();
                                ImageView appicon;

                                appicon = pi.applicationInfo.setImageDrawable(packageManager);
                                Log.e("TAG", "Permission found for "+ appname);

                                internetArray.add(appname);
                            }
            }
        }
    }

} //getPermissions 方法结束

编辑:我已经设法开始工作并在数组列表中显示。

4

1 回答 1

2
public void getPermissions(Context context) {
     PackageManager packageManager = context.getPackageManager();
     final List<PackageInfo> apps = context.getPackageManager()
         .getInstalledPackages(PackageManager.GET_PERMISSIONS);

     for (PackageInfo pi : apps) {
         String[] permissions = pi.requestedPermissions;
         if (permissions != null) {
             for (String permission : permissions) {
                 Log.d("TAG", permission);
                 if (permission.equals("android.permission.INTERNET")) {
                     // do something
                 }
             }
         }
     }
}
于 2012-07-23T23:21:55.993 回答