Android 事物的位置服务已禁用
Location Services disabled on Android Things
尝试 运行 BLE Indoor Positioning Demo App on Android Things (using the NXP i.MX7D Developer Kit) 时,我得到 Bluetooth scanning error: Location Services disabled (code 4)
。
E/BluetoothClient: Bluetooth scanning error: Location Services disabled (code 4)
W/System.err: com.polidea.rxandroidble.exceptions.BleScanException: Location Services disabled (code 4)
W/System.err: at com.polidea.rxandroidble.internal.scan.ScanPreconditionsVerifierApi18.verify(ScanPreconditionsVerifierApi18.java:31)
W/System.err: at com.polidea.rxandroidble.internal.scan.ScanPreconditionsVerifierApi24.verify(ScanPreconditionsVerifierApi24.java:38)
W/System.err: at com.polidea.rxandroidble.RxBleClientImpl.call(RxBleClientImpl.java:114)
W/System.err: at com.polidea.rxandroidble.RxBleClientImpl.call(RxBleClientImpl.java:111)
W/System.err: at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
W/System.err: at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
W/System.err: at rx.Observable.subscribe(Observable.java:10352)
W/System.err: at rx.Observable.subscribe(Observable.java:10319)
W/System.err: at rx.Observable.subscribe(Observable.java:10227)
W/System.err: at com.nexenio.bleindoorpositioningdemo.bluetooth.BluetoothClient.startScanning(BluetoothClient.java:79)
W/System.err: at com.nexenio.bleindoorpositioningdemo.HomeActivity.onResume(HomeActivity.java:108)
W/System.err: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355)
W/System.err: at android.app.Activity.performResume(Activity.java:7118)
W/System.err: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556)
W/System.err: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621)
W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862)
W/System.err: at android.app.ActivityThread.-wrap11(Unknown Source:0)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err: at android.os.Looper.loop(Looper.java:164)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6494)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
该应用程序使用 RxAndroidBle 来处理 Android 的蓝牙堆栈。它还在清单中声明了这些权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
据我了解,Android Things 应该会在安装时或重启后自动授予这些权限。
我不知道应该如何手动或以编程方式启用定位服务。
问题不在于权限。 RxAndroidBle 库对位置服务做出了一些假设,这些假设不一定适合 Android Things(因为这些设置实际上并不由用户控制)。库检查失败的原因是 NETWORK_PROVIDER
未启用,而 GPS_PROVIDER
仅在您注册了 GPS 驱动程序时才启用。但是,您实际上不需要其中任何一个来进行 BLE 扫描。
幸运的是,RxAndroidBle 的作者最近更改了代码以验证是否启用了定位模式设置。此检查将传递 Android 事物,因此在您的情况下,您可能只需要将库依赖项更新为 1.5:
dependencies {
...
implementation "com.polidea.rxandroidble:rxandroidble:1.5.0"
}
尝试 运行 BLE Indoor Positioning Demo App on Android Things (using the NXP i.MX7D Developer Kit) 时,我得到 Bluetooth scanning error: Location Services disabled (code 4)
。
E/BluetoothClient: Bluetooth scanning error: Location Services disabled (code 4)
W/System.err: com.polidea.rxandroidble.exceptions.BleScanException: Location Services disabled (code 4)
W/System.err: at com.polidea.rxandroidble.internal.scan.ScanPreconditionsVerifierApi18.verify(ScanPreconditionsVerifierApi18.java:31)
W/System.err: at com.polidea.rxandroidble.internal.scan.ScanPreconditionsVerifierApi24.verify(ScanPreconditionsVerifierApi24.java:38)
W/System.err: at com.polidea.rxandroidble.RxBleClientImpl.call(RxBleClientImpl.java:114)
W/System.err: at com.polidea.rxandroidble.RxBleClientImpl.call(RxBleClientImpl.java:111)
W/System.err: at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
W/System.err: at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
W/System.err: at rx.Observable.subscribe(Observable.java:10352)
W/System.err: at rx.Observable.subscribe(Observable.java:10319)
W/System.err: at rx.Observable.subscribe(Observable.java:10227)
W/System.err: at com.nexenio.bleindoorpositioningdemo.bluetooth.BluetoothClient.startScanning(BluetoothClient.java:79)
W/System.err: at com.nexenio.bleindoorpositioningdemo.HomeActivity.onResume(HomeActivity.java:108)
W/System.err: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355)
W/System.err: at android.app.Activity.performResume(Activity.java:7118)
W/System.err: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556)
W/System.err: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621)
W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862)
W/System.err: at android.app.ActivityThread.-wrap11(Unknown Source:0)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err: at android.os.Looper.loop(Looper.java:164)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6494)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
该应用程序使用 RxAndroidBle 来处理 Android 的蓝牙堆栈。它还在清单中声明了这些权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
据我了解,Android Things 应该会在安装时或重启后自动授予这些权限。
我不知道应该如何手动或以编程方式启用定位服务。
问题不在于权限。 RxAndroidBle 库对位置服务做出了一些假设,这些假设不一定适合 Android Things(因为这些设置实际上并不由用户控制)。库检查失败的原因是 NETWORK_PROVIDER
未启用,而 GPS_PROVIDER
仅在您注册了 GPS 驱动程序时才启用。但是,您实际上不需要其中任何一个来进行 BLE 扫描。
幸运的是,RxAndroidBle 的作者最近更改了代码以验证是否启用了定位模式设置。此检查将传递 Android 事物,因此在您的情况下,您可能只需要将库依赖项更新为 1.5:
dependencies {
...
implementation "com.polidea.rxandroidble:rxandroidble:1.5.0"
}