androidlocationlocation-services

LocationSettingsRequest request does not work on Xiaomi


I try to show popup for users who have turned off Location Services:

val locationRequest = LocationRequest.create()
        .setInterval(TimeUnit.SECONDS.toMillis(1))
        .setFastestInterval(TimeUnit.SECONDS.toMillis(1))
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
    val builder = LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
    LocationServices
        .getSettingsClient(this)
        .checkLocationSettings(builder.build())
        .addOnSuccessListener(this) { response: LocationSettingsResponse? ->
            
        }
        .addOnFailureListener(this) { ex ->
            if (ex is ResolvableApiException) {
                // Location settings are NOT satisfied,  but this can be fixed  by showing the user a dialog.
                try {
                    // Show the dialog by calling startResolutionForResult(),  and check the result in onActivityResult().
                    val resolvable = ex as ResolvableApiException
                    resolvable.startResolutionForResult(
                        this,
                        REQUEST_CODE_CHECK_SETTINGS
                    )
                } catch (sendEx: SendIntentException) {
                    // Ignore the error.
                }
            }
        }

This code piece works very well for Samsungs, but whenever a user with XIAMO REDMI NOTE 10 tests it, popup does not appear.


Solution

  • "The pop up does not appear" is not really an error description, EUR 200 would be a physical device. They likely run Android 11 with MIUI 12.5 ... while most cloud testing is Xiaomi Redmi Note 7, with Android 9. Reports suggest, to at least update the state-owned GPS-A IP address:

    Hi, just found that the supl server in the Location/A-GPS settings is set to a Chinese ip address (221.176.0.55, resolves to chinamobile.com) I guess it's a remnant from the China rom, for Europe it should probably be set to supl.google.com or perhaps supl.vodafone.com.


    It may well be, that Google Play Services aren't installed. In such case one can only build as a separate product flavor, targeting these devices in particular eg. with googleImplementation using LocationRequest, xiaomiImplementation using whatever location provider available.
    Being able to run Google Maps or Google Earth is no problem, but this does not imply Google Play Services would also be installed - as they'd be required for location and push notifications.


    According to some "authoritative source", GMS aren't banned on Xiaomi:

    https://twitter.com/Xiaomi/status/1354489349442691074

    But they cannot be assumed to be available either (by default).


    You might be looking for "Fused Location Provider by Xiaomi Inc." aka com.xiaomi.location.fused, instead of com.android.location.fused. com.android.internal.R.array.config_locationProviderPackageNames is being used for lookup.