简体   繁体   English

以编程方式检查 android 设备是否有 Google Play?

[英]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.

相关问题 如何检查Android设备是否已安装Google Play? - How to check if an android device has Google Play installed? 如何检查Android设备是否具有在10.2或更高版本上运行的Google Play服务 - How to check the whether the android device has google play services running on 10.2 or greater 是否可以通过编程方式检查谷歌地图是否在Android设备中被阻止? - Is it possible to check if google map is blocked in android device programmatically? 如何检查用户是否在 Android、Google Play 中拥有有效订阅? - How to check if the user has an active subscription in Android, Google Play? 如何检查当前的Android设备是否具有Google的位置服务? - How to check if the current Android device has Google's location service? 以编程方式检查设备是否具有 NFC 阅读器 - Check programmatically if device has NFC reader 如何检查是否可以以编程方式重新启动 Android 设备? - How to check if an Android device can be rebooted programmatically? 在Android中以编程方式从谷歌播放更新应用程序 - Update app from google play programmatically in android 没有 Play 服务的设备是否需要 Google Play 服务类路径? - Does Google Play Services Classpath necessary for device that has no Play Services? 以编程方式将 Google 帐户注册到 Android 设备 - Registering a Google account to Android device programmatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM