How to detect if Google Play is installed? (Not Market)

前端 未结 5 1240
[愿得一人]
[愿得一人] 2021-01-02 20:43

Whether the app installed is called Google Play or Market, the package name is the same com.android.vending.

I need to be able to detect whether the app

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 20:47

    You can use this simple piece of code, its easy and to the point with a consideration for not re-inventing the wheel using GooglePlayServicesUtil:

    public static boolean isPlayStoreInstalled(Context context){
    try {
        context.getPackageManager()
                .getPackageInfo(GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
    }
    

    This will require you to add this to your dependencies:

    compile 'com.google.android.gms:play-services-base:[PLAY_SERVICES_VERSION]'
    

    Latest play-services version is now: 10.0.1

提交回复
热议问题