Detect an application is installed or not?

From Android How-to's

If you ever need to know if a particular app is installed on the user's device, you can use the PackageManager. From a Context class (e.g. an Activity or a Service) you can call getPackageManager(). This gives you a variety of methods, one of which is getPackageInfo(). Below is a method you might use. You might call it like this:

isAppInstalled("com.simexusa.campusmaps_full");

private boolean isAppInstalled(String packageName) {
    PackageManager pm = getPackageManager();
    boolean installed = false;
    try {
       pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
       installed = true;
    } catch (PackageManager.NameNotFoundException e) {
       installed = false;
    }
    return installed;
}

  1. You need to create a web page that user lands on if the app is not installed. Say http://www.yourcompany.com/android/android_app_is_not_installed_landing_page.html

  2. The app needs to register in manifest XML file host www.yourcompany.com, schema “http” and the path param to app not install landing page in the manifest intent filter:

    <!-- These intents are used to launch the app from the web page-->
    <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="http"
            android:host="www.yourcompany.com"
            android:path="/android/android_app_is_not_installed_landing_page.html" 
      />
    </intent-filter>
    
  3. Now in the web page that invokes your app you specify full link to android_app_is_not_installed_landing_page.html followed by whatever params you want to pass to the app:

http://www.yourcompany.com/android/ android_app_is_not_installed_landing_page.html? '>Click here to launch the app if it is installed

If the app is installed it will be launched and passed entire http://www.yourcompany.com/android/android_app_is_not_installed_landing_page.html?' in intent that it needs to parse, extract the and do whatever it is supposed to do.

If the app is not installed, then the Android Web browser will open “Android app not installed” landing page http://www.yourcompany.com/android/android_app_is_not_installed_landing_page.html o . That page should message user to install the app and provide the link to install it from Android marketplace.

found this write up here: https://groups.google.com/forum/m/?fromgroups#!topic/android-developers/RGLHkGUpRoA


In my custom Helper.java

public static boolean isPackageInstalled(Context context, String packageName)
{
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        Log.d("Tag",packageName + " not installed");
    }
    return false;
}

Call it by

Helper.isPackageInstalled(yourActivity.this,"app_package_name")

Tags:

Android