Reputation: 1
I've already done this for iPhone app detection, using the meta tag described here:
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
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
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