Rom*_*omi 3 permissions android
我正在尝试为以下给出的代码列出所选应用程序中每个权限的保护级别。但是我不知道如何完成它。
ArrayList<String> list_permission = new ArrayList<String>();
String[] reqp = info.requestedPermissions;
if (reqp != null) {
for (i = 0; i < reqp.length; i++) {
k = i + 1;
String a = reqp[i];
if (a.contains("android.permission.")) {
String aa[] = a.split("android.permission.");
list_permission.add(aa[1]);
} else {
list_permission.add(a);
}
}
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我这个忙...只是想在权限前添加保护级别。
您可以使用PackageManager类的getPermissionInfo()方法获取任何特定权限的PermissionInfo对象。PermissionInfo对象具有Property Lavel属性,可用于检查任何权限的保护级别...您可以根据PermissoinInfo类中定义的常量(如)进行检查 PROTECTION_FLAG_SYSTEM。
像下面的代码:
for (PermissionInfo permission : packageInfo.permissions) {
// Dump permission info
String protectionLevel;
switch(permission.protectionLevel) {
case PermissionInfo.PROTECTION_NORMAL : protectionLevel = "normal"; break;
case PermissionInfo.PROTECTION_DANGEROUS : protectionLevel = "dangerous"; break;
case PermissionInfo.PROTECTION_SIGNATURE : protectionLevel = "signature"; break;
case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM : protectionLevel = "signatureOrSystem"; break;
default : protectionLevel = "<unknown>"; break;
}
Log.i("PermissionCheck", permission.name + " " + protectionLevel);
}
Run Code Online (Sandbox Code Playgroud)
更新:
获得以下防护等级requestedPermissions:
String[] reqp = info.requestedPermissions;
String perm = reqp[i];
if (perm.contains("android.permission.")) {
try {
PermissionInfo pi = getPackageManager().getPermissionInfo(perm, PackageManager.GET_META_DATA);
String protctionLevel = "unknown";
switch(pi.protectionLevel) {
case PermissionInfo.PROTECTION_NORMAL : protctionLevel = "normal"; break;
case PermissionInfo.PROTECTION_DANGEROUS : protctionLevel = "dangerous"; break;
case PermissionInfo.PROTECTION_SIGNATURE : protctionLevel = "signature"; break;
case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM : protctionLevel = "signatureOrSystem"; break;
case PermissionInfo.PROTECTION_FLAG_SYSTEM : protctionLevel = "system"; break;
default : protctionLevel = "<unknown>"; break;
}
list_permission.add(perm + " "+protctionLevel);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
list_permission.add(perm);
}
Run Code Online (Sandbox Code Playgroud)
以下行仅适用于API级别16或更高版本:
case PermissionInfo.PROTECTION_FLAG_SYSTEM : protctionLevel = "system"; break;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2955 次 |
| 最近记录: |