BLE 扫描的 SCAN_FAILED_APPLICATION_REGISTRATION_FAILED 的解决方案? [英] Solution for BLE scan's SCAN_FAILED_APPLICATION_REGISTRATION_FAILED?

查看:36
本文介绍了BLE 扫描的 SCAN_FAILED_APPLICATION_REGISTRATION_FAILED 的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Android 应用扫描 BLE 设备,从某个时间点开始失败并显示错误代码 2 (ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED).我使用的是 Nexus 9、5.0.1 Lollipop.

My Android app scans BLE devices, and from a certain point it start to fails with error code 2 (ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED). I'm using Nexus 9, 5.0.1 Lollipop.

即使我重新启动应用程序后,此问题仍然存在,当我从设置"中重新启动蓝牙服务时,我终于可以解决问题.但是这个问题反复出现,我认为我的编码方式错误;BLE 相关的 API 是新的,信息很少.

This problem continued even after I relaunched the app, and when I restarted the Bluetooth service from Settings, I could finally get rid of the problem. But this problem is recurring, and I think I'm coding in a wrong way; BLE related APIs are new and there is few information.

有没有人知道这个错误的一般解决方案,最好不需要重启蓝牙服务?尽管此错误代码记录在 Android API 参考中,但我不知道如何正确处理.

Does anyone know a general solution for this error, preferably not requiring restart of the Bluetooth service? Even though this error code is documented in Android API reference, I don't know how to handle it properly.

推荐答案

原来蓝牙 LE 需要 AndroidManifest.xml 中的以下 Android 应用程序权限:

It turns out that Bluetooth LE requires the following Android application permissions in AndroidManifest.xml:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<!--BLE scanning is commonly used to determine a user's location with Bluetooth LE beacons. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- if your app targets API level 21 or higher. -->
<uses-feature android:name="android.hardware.location.gps" />

<!--app is available to BLE-capable devices only. -->
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

除了主要活动:

// onResume()
if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
        android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
} else {
    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
            REQUEST_LOCATION_ENABLE_CODE);
}

这篇关于BLE 扫描的 SCAN_FAILED_APPLICATION_REGISTRATION_FAILED 的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆