[英]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: 我已经使用此处描述的meta标签对iPhone应用程序进行了检测:
http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html 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. 现在,我尝试对Droid-app嗅探执行相同的操作。 Basically, I want to check if the user has the 'sniffing' app installed or not. 基本上,我想检查用户是否安装了“嗅探”应用程序。
How do I detect whether or not a smartphone has an Android app installed? 如何检测智能手机是否已安装Android应用程序?
In order to make code work change "com.your.package.appname.id"
with the application id. 为了使代码正常工作,请使用应用程序ID更改"com.your.package.appname.id"
。
id is the app package and also the market url eg. id是应用程序包,也是市场网址,例如。 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
市场上的gmail应用程序网址为https://play.google.com/store/apps/details?id=com.google.android.gm
为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 ;
}
}
From this: How to get a list of installed android applications and pick one to run 从此: 如何获取已安装的android应用程序列表并选择一个以运行
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 现在,从pkgAppList您可以查看该应用程序是否已安装
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.