【问题标题】:Why does the Android version of an app require COARSE LOCATION permission to access bluetooth?为什么 Android 版应用需要 COARSE LOCATION 权限才能访问蓝牙?
【发布时间】:2019-01-28 07:46:13
【问题描述】:

我正在开发的 react-native 应用程序使用蓝牙。在 IOS 版本中,唯一需要用户确认的权限是 attemptToTriggerLEPairing。但是,在 Android 版本的应用程序中,有一个方法包含以下内容:

PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION)
        .then(granted => {
            if (granted === PermissionsAndroid.RESULTS.GRANTED || granted === true) {
                this.startScan();
                return;
            }
            return PermissionsAndroid.request(
                PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION, {
                    'title': I18n.t('permission_location_title'),
                    'message': I18n.t('permission_location_desc')
                }
            )
                .then(granted => {
                    if (granted === PermissionsAndroid.RESULTS.GRANTED || granted === true) {
                        this.startScan();
                    }
                })
        })
        .catch(error => {
            // TODO: error;
        });

为什么安卓版需要粗定位,而IOS版不需要?

【问题讨论】:

    标签: android react-native bluetooth permissions


    【解决方案1】:

    正如你在官方documentation 上看到的那样

    注意:LE 信标通常与位置相关联。为了使用 BluetoothLeScanner,您必须通过以下方式请求用户的许可 声明 ACCESS_COARSE_LOCATION 或 ACCESS_FINE_LOCATION 应用清单文件中的权限。如果没有这些权限, 扫描不会返回任何结果。

    【讨论】:

    • 感谢您在编辑中包含指向文档的链接!
    【解决方案2】:

    随着 Android 10 的推出,引入了一些更改 documentation

    如果您的应用面向 Android 10 或更高版本,则它必须具有 ACCESS_FINE_LOCATION 权限才能使用 Wi-Fi、Wi-Fi Aware 或蓝牙 API 中的多种方法。以下部分列出了受影响的类和方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 1970-01-01
      • 2011-01-23
      • 2015-08-28
      • 2011-07-15
      • 1970-01-01
      相关资源
      最近更新 更多