如何使用 AndroidThings 接受 BluetoothLE 的位置权限?
How to accept location permissions for BluetoothLE with AndroidThings?
我在低功耗蓝牙设备上使用 androidthings SDK 的预览版 3。
为了启用蓝牙,我必须调用以下代码,以绕过向用户请求权限:
mBluetoothAdapter.enable()
但是我在扫描时遇到了 SecurityException:
java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
使用 Vysor,我通过以下请求请求权限并接受权限来解决这个问题:
requestPermissions(new String[] {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSIONS_CODE);
有没有办法在不需要使用屏幕的情况下接受权限?
根据 Android 事情 platform overview docs:
Requesting Permissions at Runtime is not supported because embedded devices aren't guaranteed to have a UI to accept the runtime dialog. Declare permissions that you need in your app's manifest file. All normal and dangerous permissions declared in your app's manifest are granted at install time.
您看到 SecurityException
的原因是 release notes 中列出的以下已知问题:
Dangerous permissions requested by apps are not granted until the next device reboot.
安装应用后重启设备将在您的应用清单中授予新权限。您可以在开发过程中使用的另一种方法是使用 -g
标志直接在 ADB 上安装:
$ adb install -g <APK File>
这将在安装时授予危险权限。
我在低功耗蓝牙设备上使用 androidthings SDK 的预览版 3。
为了启用蓝牙,我必须调用以下代码,以绕过向用户请求权限:
mBluetoothAdapter.enable()
但是我在扫描时遇到了 SecurityException:
java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
使用 Vysor,我通过以下请求请求权限并接受权限来解决这个问题:
requestPermissions(new String[] {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSIONS_CODE);
有没有办法在不需要使用屏幕的情况下接受权限?
根据 Android 事情 platform overview docs:
Requesting Permissions at Runtime is not supported because embedded devices aren't guaranteed to have a UI to accept the runtime dialog. Declare permissions that you need in your app's manifest file. All normal and dangerous permissions declared in your app's manifest are granted at install time.
您看到 SecurityException
的原因是 release notes 中列出的以下已知问题:
Dangerous permissions requested by apps are not granted until the next device reboot.
安装应用后重启设备将在您的应用清单中授予新权限。您可以在开发过程中使用的另一种方法是使用 -g
标志直接在 ADB 上安装:
$ adb install -g <APK File>
这将在安装时授予危险权限。