How to detect if Google Play is installed? (Not Market)(如何检测是否安装了 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,除了 versionCode 和 versionName 没有任何帮助.
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 应用的第一个 versionCode 或 versionName 是什么吗?
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?(不是市场)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检测是否安装了 Google Play?(不是市场)
基础教程推荐
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
