1

此代码将列出已安装 apk 文件的权限。

    StringBuffer appNameAndPermissions=new StringBuffer();
    PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    for (ApplicationInfo applicationInfo : packages) {
    Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
    try {
    PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
                  appNameAndPermissions.append(packageInfo.packageName+"*:\n");
     //Get Permissions
    String[] requestedPermissions = packageInfo.requestedPermissions;
     if(requestedPermissions != null) {
     for (int i = 0; i < requestedPermissions.length; i++) {
     Log.d("test", requestedPermissions[i]);
    appNameAndPermissions.append(requestedPermissions[i]+"\n");
    }
     appNameAndPermissions.append("\n");

    }
    } catch (NameNotFoundException e) {
     e.printStackTrace();
    }}

同样,我需要一个输入 .apk 文件并输出权限的代码

4

0 回答 0