[英]Programmatically check if android device has Google Play?
Currently there are some devices that doesn't have Google Play (Huawei Devices), is there a way for me to check programmatically if the device doesn't have one?目前有一些设备没有 Google Play(华为设备),如果设备没有,我有没有办法以编程方式检查? I wanted to use the in-app-update feature: https://developer.android.com/guide/playcore/in-app-updates and check if the device has a Google PlayStore first.
我想使用应用内更新功能: https://developer.android.com/guide/playcore/in-app-updates并首先检查设备是否有 Google PlayStore。
What I have tried so far: using Uri.parse("market://details?id=" + appPackageName)
but you need to start the activity first to confirm it exists?到目前为止我已经尝试过:使用
Uri.parse("market://details?id=" + appPackageName)
但您需要先启动活动以确认它存在? I'd like to know if there are better ways to do it.我想知道是否有更好的方法来做到这一点。
You can use the following code to check whether the android device has Google Play:您可以使用以下代码检查android设备是否有Google Play:
boolean flag = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == com.google.android.gms.common.ConnectionResult.SUCCESS
If flag == true
, then GMS is enable in device.如果
flag == true
,则 GMS 在设备中启用。
If flag == false
, then GMS is disable in device.如果
flag == false
,则 GMS 在设备中被禁用。
You can check if the package com.android.vending
exists or not您可以检查 package
com.android.vending
存在
public static boolean isPackageInstalled(String packageName, PackageManager packageManager) {
try {
return packageManager.getApplicationInfo(packageName, 0).enabled;
}
catch (PackageManager.NameNotFoundException e) {
return false;
}
}
And you can do like this in your activity你可以在你的活动中这样做
if(isPackageInstalled("com.android.vending", getPackageManager())){
// play store is installed
}else{
// play store is installed
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.