如何检测是否安装了 Google Play?(不是市场)

How to detect if Google Play is installed? (Not Market)(如何检测是否安装了 Google Play?(不是市场))
本文介绍了如何检测是否安装了 Google Play?(不是市场)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论安装的应用是Google Play还是Market,包名都是一样的com.android.vending.

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

我需要能够检测应用程序是 Google Play 还是 Market,我已经检查了 PackageInfo,除了 versionCodeversionName 没有任何帮助.

I need to be able to detect whether the app is Google Play or Market, I've checked in PackageInfo and nothing except versionCode and versionName can be of help.

有人知道 Google Play 应用的第一个 versionCodeversionName 是什么吗?

Does anyone know what the first versionCode was or versionName was for Google Play app?

如果有人知道任何其他检测方法,请告诉我.

If anyone knows any other way of detecting this let me know.

推荐答案

我想出了如何检查应用程序标签.我正在使用调试器查看 packageInfo 中返回的所有内容,这就是我最初没有看到它的原因.

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

这篇关于如何检测是否安装了 Google Play?(不是市场)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)