Android电子市场或Google Apps的软件包名称是什么

时间:2010-12-14 12:15:45

标签: android

我需要检查Android Market是否像这样安装

    /*
     * Test for existence of Android Market
     */
    boolean androidMarketExists = false;
    try{
        ApplicationInfo info = getPackageManager()
                             .getApplicationInfo("com.google.process.gapps", 0 );
        //application exists
        androidMarketExists = true;
    } catch( PackageManager.NameNotFoundException e ){
        //application doesn't exist
        androidMarketExists = false;
    }

但我不知道com.google.process.gapps是否是具有Android市场的软件包。

2 个答案:

答案 0 :(得分:19)

这是com.android.vending(在我的Galaxy S上),这是更好的方法来查找...通过查询谁处理market:// URIs。

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("market://search?q=foo"));
    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);

如果列表中至少有一个条目,那么市场就在那里。

答案 1 :(得分:1)

您的代码是正确的,只需要进行细微更改

查看下面修改的代码:

boolean androidMarketExists = false;
    try{
        ApplicationInfo info = getPackageManager().getApplicationInfo("com.android.vending", 0 );
        if(info.packageName.equals("com.android.vending"))
            androidMarketExists = true;
        else
            androidMarketExists = false;
    } catch(PackageManager.NameNotFoundException e ){
        //application doesn't exist
        androidMarketExists = false;
    }
    if(!androidMarketExists){
        Log.d(LOG_TAG, "No Android Market");
        finish();
    }
    else{
        Log.d(LOG_TAG, "Android Market Installed");
    }