首页 > 解决方案 > 如何检查设备是否启用谷歌移动服务?

问题描述

我必须检查设备上的谷歌服务是否处于活动状态。我怎样才能检查它?只看玩服务就够了?

我需要这个检查华为服务。

标签: javaandroidkotlingoogle-play-serviceshuawei-mobile-services

解决方案


您应该使用GoogleApiAvailabilityAPI。GooglePlayServicesUtilAPI 已弃用,请勿使用。

爪哇:

public boolean isGooglePlayServicesAvailable(final Context context) {
    return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS;
}

科特林:

fun Context.isGooglePlayServicesAvailable(): Boolean =
    GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS

推荐阅读