LocationSettingsRequest 请求不适用于小米

LocationSettingsRequest request does not work on Xiaomi

我尝试为关闭定位服务的用户显示弹出窗口:

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.
                }
            }
        }

此代码片段适用于三星手机,但无论何时使用 XIAMO REDMI NOTE 10 的用户对其进行测试,都不会出现弹出窗口。

“没有出现弹出窗口”并不是真正的错误描述,200 欧元将是一个物理设备。他们可能 运行 Android 11 MIUI 12.5 ...而大多数云测试是小米 Redmi Note 7,Android 9。报告建议,至少更新 state-owned GPS-A IP地址:

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.

  • 在设置中搜索“A-GPS”。
  • 将 A-GPS 服务器 221.176.0.55 替换为 supl.google.com

很可能 Google Play 服务没有安装。在这种情况下,人们只能构建一个单独的产品风味,特别针对这些设备,例如。 googleImplementation 使用 LocationRequestxiaomiImplementation 使用任何可用的位置提供商。
能够 运行 Google 地图或 Google 地球没问题,但这并不意味着 Google Play 服务也将被安装 - 因为它们是定位所必需的和推送通知。


根据一些“权威人士”的说法,小米并未禁用GMS:

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

但也不能假定它们可用(默认情况下)。


您可能正在寻找“小米公司的 Fused Location Provider”。又名 com.xiaomi.location.fused,而不是 com.android.location.fusedcom.android.internal.R.array.config_locationProviderPackageNames 正在用于查找。