【问题标题】:What is the package name of the Android Market or Google AppsAndroid Market 或 Google Apps 的软件包名称是什么
【发布时间】:2010-12-14 12:15:44
【问题描述】:

我需要检查一下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 market的包。

【问题讨论】:

    标签: android


    【解决方案1】:

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

        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);
    

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

    【讨论】:

    • 我需要把 foo 改成真正的包吗?
    • 我不完全同意这一点……手机上可能还有其他与谷歌无关的市场应用程序,这些应用程序也可以处理市场://意图。如果您需要专门检查 Google 的市场应用程序,我认为您可能需要以某种方式在包管理器中检查 com.android.vending。
    【解决方案2】:

    您的代码是正确的,只需稍作改动

    查看下面修改的代码:

    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");
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多