0

我有这段代码来获取所有使用 Internet 权限的应用程序,但是出了点问题,请帮助我 :)

public String[] getAppsWithNet() {

    int flag = 0;
    String[] appsNet = new String[50];
    PackageManager p = c.getPackageManager();
    final List<PackageInfo> apps = p.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    for (PackageInfo pkg : apps) {
        for (String permission : pkg.requestedPermissions) {
            if (p.PERMISSION_GRANTED == p.checkPermission(Manifest.permission.INTERNET, pkg.packageName)) {
                appsNet[flag] = pkg.packageName;
                flag++;
            }
        }
    }
    return appsNet;
}

预先感谢...

4

1 回答 1

0

PackageInfo.requestedPermissions返回一个字符串类型的数组而不是字符串,因此您需要将代码更改为:

List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
for(PackageInfo pack : packages)
{
   PackageInfo permissionInfo = null;  
    permissionInfo = getPackageManager().getPackageInfo(pack.packageName, PackageManager.GET_PERMISSIONS);
    if(permissionInfo != null){  
         String[] permissions = permissionInfo.requestedPermissions;
          //YOUR CODE HERE
      }
}
于 2012-11-08T13:38:41.707 回答