0

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

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

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

4

2 回答 2

1

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

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

id 是应用程序包,也是市场 URL,例如。市场上的 gmail 应用程序 url 是https://play.google.com/store/apps/details?id=com.google.android.gmid/packagename 是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 ;
}
}
于 2013-03-26T19:08:14.430 回答
0

由此:如何获取已安装的 android 应用程序列表并选择一个运行

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

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

于 2013-03-26T19:06:30.747 回答