[英]How to check if an android device has Google Play installed?
I am trying to check if the device has Google Play installed or not in my app, but seems there is no way to do that. 我正在尝试检查设备是否在我的应用程序中安装了Google Play,但似乎无法执行此操作。 I followed the post HERE but still doesn't work, always return true even i was testing with an emulator, it has com.android.vending installed. 我按照这里的帖子,但仍然无法正常工作,即使我正在使用模拟器进行测试,也始终返回true,它安装了com.android.vending。 So am i checking the wrong package name? 我是否检查了错误的包裹名称? Any ideas for that? 有什么想法吗?
Thanks in advance! 提前致谢!
Follow Dcoumentation to check if the device has Google Play Service available. 按照Dcoumentation检查设备是否有可用的Google Play服务。
In Short, simply: 简而言之,简单地:
// Getting status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status==ConnectionResult.SUCCESS)
//Google Play Services are available
else{
//Google Play Services are not available
}
Hope this will help you :) 希望这个能对您有所帮助 :)
Finally, found a way to check Google Play installed, here is the code: 最后,找到一种检查安装的Google Play的方法,下面是代码:
public static boolean isPackageInstalled(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 = (!TextUtils.isEmpty(label) && label.startsWith("Google Play"));
} catch(PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.