Determine list of permissions used by an installed application in Android

后端 未结 4 949
难免孤独
难免孤独 2020-12-09 06:42

I have to determine list of permission used each by the installed application on my device.

I have got the list of applications installed and there package name usin

相关标签:
4条回答
  • 2020-12-09 07:13

    Here how to retrieve the list of the apps installed on an Android device, and the permissions used by every app.

    private static final String TAG = "MyActivity";  
    ...
    
    final PackageManager pm = getPackageManager();
    final List<ApplicationInfo> installedApps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    
    for ( ApplicationInfo app : installedApps ) {
        //Details:
        Log.d(TAG, "Package: " + app.packageName);
        Log.d(TAG, "UID: " + app.uid);
        Log.d(TAG, "Directory: " + app.sourceDir);
    
        //Permissions:
        StringBuffer permissions = new StringBuffer();
    
        try {
            PackageInfo packageInfo = pm.getPackageInfo(app.packageName, PackageManager.GET_PERMISSIONS);
    
            String[] requestedPermissions = packageInfo.requestedPermissions;
            if ( requestedPermissions != null ) {
                for (int i = 0; i < requestedPermissions.length; i++) {
                    permissions.append(requestedPermissions[i] + "\n");
                }
    
                Log.d(TAG, "Permissions: " + permissions);
            }
        }
        catch ( PackageManager.NameNotFoundException e ) {
            e.printStackTrace();
        }
    }
    
    0 讨论(0)
  • 2020-12-09 07:24

    Check out freetaskmanager

            // Loop through all installed packaged to get a list of used permissions and PackageInfos
        for (PackageInfo pi : appList) {            
            // Do not add System Packages
            if ((pi.requestedPermissions == null || pi.packageName.equals("android")) || 
                    (pi.applicationInfo != null && (pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)) 
                continue;
    
    
            for (String permission : pi.requestedPermissions) {
                Map<String, String> curChildMap = new HashMap<String, String>();
                try {
                    PermissionInfo pinfo = mPm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
                    CharSequence label = pinfo.loadLabel(mPm);
                    CharSequence desc = pinfo.loadDescription(mPm);
                } catch (NameNotFoundException e) {
                    Log.i(TAG, "Ignoring unknown permission " + permission);
                    continue;
                }
            }
        }
    
    0 讨论(0)
  • 2020-12-09 07:27

    This is the only thing I found, though I've not tested it out.

    Let me know if it works for any one:

    pm.getPackageInfo(rInfo.activityInfo.applicationInfo.packageName, packageManager.GET_PERMISSIONS);
    
    0 讨论(0)
  • 2020-12-09 07:30

    So i coded it.i needed not just the permissions but also the recievers and services.pls see the following code,hope its useful for others.

    PackageManager p = this.getPackageManager();
      final List <PackageInfo> appinstall=p.getInstalledPackages(PackageManager.GET_PERMISSIONS|PackageManager.GET_RECEIVERS|
          PackageManager.GET_SERVICES|PackageManager.GET_PROVIDERS);
    
      for(PackageInfo pInfo:appinstall){
          //PermissionInfo[] permission=pInfo.permissions;
           String[] reqPermission=pInfo.requestedPermissions;
           ServiceInfo[] services=pInfo.services;
           ProviderInfo[] providers=pInfo.providers;
    
      int versionCode=pInfo.versionCode;
      Log.d("versionCode-package ",Integer.toString(versionCode));
      Log.d("Installed Applications", pInfo.applicationInfo
                .loadLabel(pm).toString());
      Log.d("packegename",pInfo.packageName.
               toString());
      if(reqPermission!=null)
        for(int i=0;i<reqPermission.length;i++)
           Log.d("permission list",reqPermission[i]);
    

    }

    NOTICE-setting flags is important otherwise it causes problem n u cnt get services ,provider NOTE- NULL CHECK IS IMP OR IT GIVES NPE

    also the previous code i wrote ws using activityInfo this one uses packageInfo .it better now i guess :) happy coding ppl :)

    0 讨论(0)
提交回复
热议问题