如何检测Android手机是否安装了特定的应用程序?

时间:2013-03-26 19:02:41

标签: android detection smartphone

我已经使用此处描述的元标记完成了iPhone应用检测:

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

现在我正在尝试为Droid-app嗅探做同样的事情。基本上,我想检查用户是否安装了“嗅探”应用程序。

2 个答案:

答案 0 :(得分:1)

如何检测智能手机是否安装了Android应用?

为了使代码更改"com.your.package.appname.id"与应用程序ID。

id是应用包,也是市场网址,例如。市场上的gmail应用网址为https://play.google.com/store/apps/details?id=com.google.android.gm,ID /包名称为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 ;
}
}

答案 1 :(得分:0)

从此: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);

现在,您可以从pkgAppList查看该应用是否已安装