Vince Match
Vince Match

Reputation: 1

How to detect whether or not an Android phone has a specific app installed?

I've already done this for iPhone app detection, using the meta tag described here:

http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

Now I'm trying to do the same for Droid-app sniffing. Basically, I want to check if the user has the 'sniffing' app installed or not.

Upvotes: 0

Views: 867

Answers (2)

madlymad
madlymad

Reputation: 6540

How do I detect whether or not a smartphone has an Android app installed?

In order to make code work change "com.your.package.appname.id" with the application id.

id is the app package and also the market url eg. gmail app url at the market is https://play.google.com/store/apps/details?id=com.google.android.gm and the id/packagename is com.google.android.gm

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;

public class Example extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //Put the package name here...
        boolean installed  =   appInstalledOrNot("com.your.package.appname.id");
        if(installed)
        {
                  System.out.println("App already installed om your android");
        }
        else
        {
            System.out.println("App is not installed om your android");
        }
    }
    private boolean appInstalledOrNot(String uri)
    {
        PackageManager pm = getPackageManager();
        boolean app_installed = false;
        try
        {
               pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
               app_installed = true;
        }
        catch (PackageManager.NameNotFoundException e)
        {
               app_installed = false;
        }
        return app_installed ;
}
}

Upvotes: 1

Roman
Roman

Reputation: 2079

From this: How to get a list of installed android applications and pick one to run

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

Now, from pkgAppList you can see if the app is installed

Upvotes: 0

Related Questions