Have both GMS and HMS in the project

前端 未结 4 731
醉梦人生
醉梦人生 2020-12-13 13:48

How does one go about having both Google Mobile Services and Huawei Mobile Services in the app?

Being that Huawei have lost the lice

4条回答
  •  既然无缘
    2020-12-13 14:23

    Before I answer your question here is short explanation what is HMS and GMS:

    • HMS stands for Huawei Mobile Services
    • GMS stands for Google Mobile Services

    You can publish your app (which is using Google's libraries) in Huawei's app store (named AppGallery) but this app will be visible and available to download only for Huawei's devices containing HMS+GMS (all devices till 2020 had HMS and GMS).

    However the newer phones i.e. Mate 30 series, P40 - will have installed only HMS. So if you want to make your app visible for all Huawei devices (HMS+GMS and HMS) then you will have to implement in you app function for detecting what service is on on user's device. It will decide what proper function to call (i.e initialize instance of Huawei Maps or Google Maps).

    Here is the code for detecting HMS and GMS:

    For Huawei Mobile Services we use:

    HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context);
    

    https://developer.huawei.com/consumer/en/doc/development/HMS-References/huaweiapiavailability

    For Google Mobile Services we use:

    GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
    

    https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability

    Here is the code how to properly handle detecting HMS and GMS:

    public static boolean isHmsAvailable(Context context) {
        boolean isAvailable = false;
        if (null != context) {
            int result = HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context);
            isAvailable = (com.huawei.hms.api.ConnectionResult.SUCCESS == result);
        }
        Log.i(TAG, "isHmsAvailable: " + isAvailable);
        return isAvailable;
    }
    
    public static boolean isGmsAvailable(Context context) {
        boolean isAvailable = false;
        if (null != context) {
            int result = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
            isAvailable = (com.google.android.gms.common.ConnectionResult.SUCCESS == result);
        }
        Log.i(TAG, "isGmsAvailable: " + isAvailable);
        return isAvailable;
    }
    

    AFAIK these classes (HuaweiApiAvailability/GoogleApiAvailability) are available if you implement any of the Huawei's kit/Google's lib.

提交回复
热议问题