Checks if the target app is installed on the device - Android App

Android examples for App:App Install

Description

Checks if the target app is installed on the device

Demo Code


//package com.java2s;

import android.content.Context;

import android.content.pm.PackageManager;

import android.support.annotation.NonNull;

public class Main {
    /**/*from   w  ww. j  a  va  2  s.  c  om*/
     * Checks if the target app is installed on the device
     * @param context
     * @param targetPackageName
     * @return
     */
    public static boolean isAppInstalled(@NonNull Context context,
            String targetPackageName) {
        PackageManager pm = context.getPackageManager();
        try {
            pm.getApplicationInfo(targetPackageName,
                    PackageManager.GET_ACTIVITIES);
            return true;
        } catch (PackageManager.NameNotFoundException ne) {
            return false;
        }
    }
}

Related Tutorials