How to check Google Mobile Services enable in device or not?

无人久伴 提交于 2021-02-11 04:26:41

问题


I have to check if google services are active on the device. How can I check it? Looking just play services is enough?

I need this check for Huawei services.


回答1:


final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (status != ConnectionResult.SUCCESS) {
        Log.e(TAG, GooglePlayServicesUtil.getErrorString(status));
                  return false;
    } else {
        Log.i(TAG, GooglePlayServicesUtil.getErrorString(status));
                   return true;
    }



回答2:


I think this code will help you

final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (status != ConnectionResult.SUCCESS) {
        Log.e(TAG, GooglePlayServicesUtil.getErrorString(status));
                  return false;
    } else {
        Log.i(TAG, GooglePlayServicesUtil.getErrorString(status));
                   return true;
    }

.

public static final int SUCCESS = 0;
public static final int SERVICE_MISSING = 1;
public static final int SERVICE_VERSION_UPDATE_REQUIRED = 2;
public static final int SERVICE_DISABLED = 3;
public static final int SIGN_IN_REQUIRED = 4;
public static final int INVALID_ACCOUNT = 5;
public static final int RESOLUTION_REQUIRED = 6;
public static final int NETWORK_ERROR = 7;
public static final int INTERNAL_ERROR = 8;
public static final int SERVICE_INVALID = 9;
public static final int DEVELOPER_ERROR = 10;
public static final int LICENSE_CHECK_FAILED = 11;
public static final int CANCELED = 13;
public static final int TIMEOUT = 14;
public static final int INTERRUPTED = 15;
public static final int API_UNAVAILABLE = 16;
public static final int SIGN_IN_FAILED = 17;



回答3:


You should use GoogleApiAvailability API. GooglePlayServicesUtil API is deprecated, don't use it.

Java:

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

Kotlin:

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



回答4:


You can use these codes to check:

boolean flag = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == com.google.android.gms.common.ConnectionResult.SUCCESS

If flag == true, then GMS is enable in device.

If flag == false, then GMS is disable in device.



来源:https://stackoverflow.com/questions/62319899/how-to-check-google-mobile-services-enable-in-device-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!