2

I want to know that the specific Application as App1 is Installed or Not on my App.
Here I don't know the actual package name of that App1(App1 is only name).
Then How to find that application is currently installed or not?
I have tried this ,

private static final String PACKAGE_NAME = "App1";

/**
 * Returns true if "App1" is installed. 
 */
public static boolean isApp1Installed( Context context )
{
    boolean output = false;
    PackageManager pm = context.getPackageManager();
    try { 
        PackageInfo pi = pm.getPackageInfo( PACKAGE_NAME, 0 );
        if( pi != null )
        {
            output = true;
        }
    } catch (PackageManager.NameNotFoundException e) {}
    return output;
}

Please Help Me..

posteritysystem
  • 973
  • 2
  • 7
  • 20

3 Answers3

3

You can use PackageManager to get a list of all installed packages by using the:

getInsatlledPackages

or a list of activities by

queryIntentActivities 

for an intent with CATEGORY_LAUNCHER

By name you can find whether the app is installed or not:

String appname = packageManager.getApplicationLabel(pk).toString();

You may also follow the below link for more help:

http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon

Hope it solves your problem.

qwerty
  • 2,392
  • 3
  • 30
  • 55
2

Qwerty is correct and you should accept his/her answer, but I'd just like to add that there are some situations where this method doesn't perform as expected. If you're checking for an app that is in the market, you shouldn't have a problem. You may have a problem (as I did) if you're checking for one of the default Android system apps. Some manufacturers replace things like the stock messaging app, and you can usually catch this by checking if the package is present. However, one manufacturer decided to replace the stock messaging app under a new package name AND leave the old package with no activities. The way I got around it was by checking the size of PackageInfo.activities. If it's empty, proceed as though the app isn't there.

Krylez
  • 17,414
  • 4
  • 32
  • 41
  • That's tricky. I don't think there's a reliable way to do it. http://stackoverflow.com/questions/1806286/getting-installed-app-size – Krylez Aug 12 '12 at 06:23
0

You can just check if there is an intent to it:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.myapp");

if (launchIntent == null) {
    // it is not installed
}
hsgubert
  • 2,266
  • 1
  • 22
  • 23