How to retrieve installed application list and permissions

In this short post i will show you how use the PackageManager class to retrieve the list of installed applications and associated permissions on your android device .

Starting from the your Activity context you can obtain an instance of PackageManager through the method called getPackageManager(). Using that class is it possible to get a list of ApplicationInfo objects containing details about apps such as MetaData, Permissions, Services or Activities.

Useful data are for example the name of the app, the packageName used to retrieve additional information with PackageManager methods and the publicSourceDir that represent a simple way to identify system or user applications.

The following code gets first of all the PackageManager object, retrieves ApplicationInfos of available apps and for each of them loads the list of permissions and the associated icon as Drawable object.

PackageManager pm = getPackageManager();
List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo applicationInfo : packages) {
Log.d(TAG, "App:"+applicationInfo.name+" Package :" + applicationInfo.packageName);
try {

PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);

//Get Permissions
String[] requestedPermissions = packageInfo.requestedPermissions;

if(requestedPermissions != null)
{
for (int i = 0; i < requestedPermissions.length; i++) {
Log.d(TAG,requestedPermissions[i]);
}
}

//Get Application Icon
Drawable appIcon = pm.getApplicationIcon(applicationInfo.packageName);

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


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box