Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of installed apps on an Android device?

Tags:

java

android

I'm making an Android launcher as an introduction to making Android apps for myself, and part of my design requires me to know how many apps are installed on a user's device, and preferably count only the ones which are normal apps that can be launched. I wish to store this number of apps in a global, integer variable. With only this goal in mind, what is the simplest way of just retrieving this number as that variable?

like image 831
MSC Avatar asked Aug 19 '16 15:08

MSC


1 Answers

You could use the getInstalledApplications() method of PackageManager.

From the documentation:

Return a List of all application packages that are installed on the device. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all applications including those deleted with DONT_DELETE_DATA (partially installed apps with data directory) will be returned.

Something like this should work:

int numberOfInstalledApps = getPackageManager(0).getInstalledApplications().size();

To filter out the system apps you could do something like this:

int numberOfNonSystemApps = 0;

List<ApplicationInfo> appList = getPackageManager().getInstalledApplications(0);
for(ApplicationInfo info : appList) {
    if((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        numberOfNonSystemApps++;
    }
}
like image 173
earthw0rmjim Avatar answered Sep 20 '22 23:09

earthw0rmjim