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

前端 未结 5 1195
[愿得一人]
[愿得一人] 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:57

    I figured out how to check the application label. I was using the debugger to see what all was being returned in packageInfo that's why I didn't see it initially.

    public static boolean isGooglePlayInstalled(Context context) {
        PackageManager pm = context.getPackageManager();
        boolean app_installed = false;
        try
        {
               PackageInfo info = pm.getPackageInfo("com.android.vending", PackageManager.GET_ACTIVITIES);
               String label = (String) info.applicationInfo.loadLabel(pm);
               app_installed = (label != null && !label.equals("Market"));
        }
        catch (PackageManager.NameNotFoundException e)
        {
               app_installed = false;
        }
        return app_installed;
    }
    

提交回复
热议问题