Check if an application is installed on the device

Asked

Viewed 3,041 times

7

I need help to check if an application is installed on the user’s device.

Situation 1: I need to perform a search on the user’s mobile and check if there are any installed applications. If you find these installed applications return through a method to the list of applications.

Situation 2: Make this list of installed applications available to be consumed by another application.

How can I do that?

1 answer

2


To get a list of information regarding all installed applications use the method getInstalledApplications() packagemanager:

PackageManager packageManager = getPackageManager();
List<ApplicationInfo> list = 
           packageManager.getInstalledApplications(PackageManager.GET_META_DATA);   

The returned list has an object Applicationinfo for each installed application.

To filter and obtain only those that are from Category "android.intent.category.LAUNCHER" use the following method:

private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {
    PackageManager packageManager = getPackageManager();
    ArrayList<ApplicationInfo> applist = new ArrayList<ApplicationInfo>();
    for (ApplicationInfo info : list) {
        try {
            if (null != packageManager.getLaunchIntentForPackage(info.packageName)) {
                applist.add(info);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return applist;
}

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.