Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the package name of the Android Market or Google Apps

Tags:

android

I need to check if the Android Market is installed like this

    /*
     * 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;
    }

But I don't know if com.google.process.gapps is the package that has android market or not.

like image 218
jax Avatar asked Dec 14 '10 12:12

jax


2 Answers

It's com.android.vending (on my Galaxy S), and here's the better way to find out... by querying for who handles 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);

If the list has at least one entry, the Market's there.

like image 74
Reuben Scratton Avatar answered Oct 16 '22 06:10

Reuben Scratton


Your code is right just needs minor changes

Check out code modified below:

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");
    }
like image 40
Akshay Chordiya Avatar answered Oct 16 '22 05:10

Akshay Chordiya