Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine list of permissions used by an installed application in Android

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 using the following code:

PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);

List<ResolveInfo> list = m.queryIntentActivities(intent,PackageManager.PERMISSION_GRANTED);

  for (ResolveInfo rInfo : list) {   
   Log.d("Installed Applications", rInfo.activityInfo.applicationInfo
     .loadLabel(pm).toString());
   Log.d("packegename",rInfo.activityInfo.applicationInfo.packageName.
           toString());
     }

How do I get permission used by each application?

like image 659
nia Avatar asked Dec 17 '22 19:12

nia


2 Answers

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 :)

like image 71
nia Avatar answered Dec 28 '22 06:12

nia


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();
    }
}
like image 23
Paolo Rovelli Avatar answered Dec 28 '22 07:12

Paolo Rovelli