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?
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 :)
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With