Skip to content

GMS vs. HMS — Platform detection

The RoadSave SDK supports both Google Mobile Services (GMS) and Huawei Mobile Services (HMS) through the bundled xmsadapter module, which routes all location and activity recognition calls to the correct underlying SDK at runtime.


How the xmsadapter works

The xmsadapter is a Huawei XMS-toolkit–generated layer that wraps org.xms.g.* equivalents over both com.google.android.gms.* (GMS) and com.huawei.hms.* (HMS) APIs. Your code only interacts with the org.xms.g.* interfaces; the adapter routes calls based on GlobalEnvSetting.

Your code
   └─ RoadSave SDK (org.xms.g.location.*)
         └─ xmsadapter
               ├─ GMS path → com.google.android.gms.location.*
               └─ HMS path → com.huawei.hms.location.*

Detecting the platform

Use RoadSave.isHmsAvailable(context) to check whether HMS Core is present on the device:

val isHms = RoadSave.isHmsAvailable(context)

This method queries HuaweiApiAvailability and returns true only if HMS Core is installed and available. On Google-services devices (where HMS Core is absent), it returns false.


Configuring GlobalEnvSetting

Call this in Application.onCreate() before any other SDK method. The RoadSave constructor also calls this internally, but an explicit call in Application.onCreate() guarantees correct routing for any background re-initialization.

// Kotlin
class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        if (RoadSave.isHmsAvailable(this)) {
            GlobalEnvSetting.useHms()
        } else {
            GlobalEnvSetting.useGms()
        }
    }
}
// Java
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        if (RoadSave.isHmsAvailable(this)) {
            GlobalEnvSetting.useHms();
        } else {
            GlobalEnvSetting.useGms();
        }
    }
}

Declare your custom Application class in AndroidManifest.xml:

<application android:name=".MyApplication" ...>

Checking the active platform at runtime

After initialization, you can query which platform the SDK is using:

val sdk = RoadSave(context)
if (sdk.isHms()) {
    // running on Huawei HMS
} else if (sdk.isGms()) {
    // running on Google GMS
}

HMS-specific manifest permissions

Huawei devices require an additional activity recognition permission:

<uses-permission android:name="com.huawei.hms.permission.ACTIVITY_RECOGNITION" />

This is safe to include on GMS devices — it is ignored when HMS is not present.


HMS Core version requirements

The SDK uses com.huawei.hms:location:6.4.0.300. The minimum HMS Core APK version required on-device is HMS Core 6.x+. Devices with older HMS Core will be prompted to update by the HMS runtime.


Devices that have both GMS and HMS

Some Huawei devices (primarily those released before the 2019 trade restrictions) have both GMS and HMS installed. In this case, isHmsAvailable returns true because HMS Core is present. The SDK routes through HMS on these devices.

If your application explicitly requires GMS routing on dual-stack devices, call GlobalEnvSetting.useGms() unconditionally — but this is not recommended for production as it will fail on HMS-only devices.