Android 设置 API 打开蓝牙以提高定位精度?

Android Settings API turn on bluetooth to improve location accuracy?

我已经使用新设置 API 在不离开我的应用程序的情况下打开 GPS。 我的 LocationRequest 如下所示:

LocationRequest mLocationRequest = new LocationRequest(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

一切正常,但对话框提示我也启用蓝牙(以及 GPS)有没有办法只启用 GPS?

我怀疑您在 LocationSettingsRequest 中错误地请求了 BLE 支持。

LocationSettingsRequest.Builder 建造者 = 新 LocationSettingsRequest.Builder() .addLocationRequest(mLocationRequestHighAccuracy) .addLocationRequest(mLocationRequestBalancedPowerAccuracy);

builder.setNeedBle(true);

如果客户端使用 BLE 扫描来获取位置,它可以通过调用 setNeedBle(boolean):

请求启用 BLE

如果您不需要 BLE,则将其设置为 false 或删除此行。

我在这里发现了同样的问题。我必须通过首先打开蓝牙然后从回调请求位置来解决这个问题。

private boolean isBluetoothEnabled() {
    if (mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        int REQUEST_ENABLE_BT = 1;
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        return false;
    }
    return true;
}