我有这个代码来获取所有使用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;
}
提前谢谢......
答案 0 :(得分:0)
PackageInfo.requestedPermissions返回一个String类型数组而不是String,因此您需要将代码更改为:
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
}
}