簡體   English   中英

Android電子市場或Google Apps的軟件包名稱是什么

[英]What is the package name of the Android Market or Google Apps

我需要檢查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市場的軟件包。

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

如果列表至少有一個條目,那么市場就在那里。

您的代碼是正確的,只需要進行細微更改

查看下面修改的代碼:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM