如何修复Android BLE SCAN_FAILED_APPLICATION_REGISTRATION_FAILED错误? [英] How to fix Android BLE SCAN_FAILED_APPLICATION_REGISTRATION_FAILED error?
问题描述
大多数情况下,它运行良好,但是有时我在尝试发现BLE设备时遇到此错误:
02-12 18:00:41.952 16178-16339/com.icrealtime.allie W/BleRpcConnectionFactory﹕ Starting discovery
02-12 18:00:41.955 16178-16339/com.icrealtime.allie D/BluetoothAdapter﹕ STATE_ON
02-12 18:00:41.957 24342-18813/? D/BtGatt.GattService﹕ registerClient() - UUID=c4a4c56d-1d10-4615-9c8d-44971bc3d6e6
02-12 18:00:41.957 24342-24384/? E/bt_btif﹕ Register with GATT stack failed.
02-12 18:00:41.957 24342-24384/? E/bt_btif﹕ Register with GATT stack failed.
02-12 18:00:41.957 24342-24370/? D/BtGatt.GattService﹕ onClientRegistered() - UUID=c4a4c56d-1d10-4615-9c8d-44971bc3d6e6, clientIf=0
02-12 18:00:41.958 16178-16190/com.icrealtime.allie D/BluetoothLeScanner﹕ onClientRegistered() - status=133 clientIf=0
02-12 18:00:41.967 16178-16178/com.icrealtime.allie E/BleRpcConnectionFactory﹕ BLE SCAN FAILED: 2
这似乎是android的内部问题,但是它可能会受到我的代码做错事情的影响.可能是什么原因以及如何解决呢?
PS. Nexus 9,Android 6.0.1
我遇到了同样的问题,这对我有用.可能看起来像是一个愚蠢的修复程序,但效果很好.
在清单文件中添加所需的蓝牙和位置许可要求后...
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION_LOCATION" />
您必须为应用程序打开FINE LOCATION或COARSE LOCATION权限. 您可以从设备上的应用程序设置中手动执行此操作,也可以将此代码段添加到onCreate()方法中.
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);
}
您还需要将int REQUEST_LOCATION_ENABLE_CODE定义为1.
Most of times it works great but sometimes i'm having this error while trying to discover BLE devices:
02-12 18:00:41.952 16178-16339/com.icrealtime.allie W/BleRpcConnectionFactory﹕ Starting discovery
02-12 18:00:41.955 16178-16339/com.icrealtime.allie D/BluetoothAdapter﹕ STATE_ON
02-12 18:00:41.957 24342-18813/? D/BtGatt.GattService﹕ registerClient() - UUID=c4a4c56d-1d10-4615-9c8d-44971bc3d6e6
02-12 18:00:41.957 24342-24384/? E/bt_btif﹕ Register with GATT stack failed.
02-12 18:00:41.957 24342-24384/? E/bt_btif﹕ Register with GATT stack failed.
02-12 18:00:41.957 24342-24370/? D/BtGatt.GattService﹕ onClientRegistered() - UUID=c4a4c56d-1d10-4615-9c8d-44971bc3d6e6, clientIf=0
02-12 18:00:41.958 16178-16190/com.icrealtime.allie D/BluetoothLeScanner﹕ onClientRegistered() - status=133 clientIf=0
02-12 18:00:41.967 16178-16178/com.icrealtime.allie E/BleRpcConnectionFactory﹕ BLE SCAN FAILED: 2
error code 2 stands for https://developer.android.com/reference/android/bluetooth/le/ScanCallback.html#SCAN_FAILED_APPLICATION_REGISTRATION_FAILED
It seems to be internal android issue, but it can be affected by my code doing something wrong. What can be the reason and how to walkaround it?
PS. Nexus 9, Android 6.0.1
I had the same issue and this worked for me. Might look like a silly fix but worked lol.
After adding the required Bluetooth and Location permission requirements in your manifest file...
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION_LOCATION" />
You must turn on the FINE LOCATION or COARSE LOCATION permissions for the app. You could do this manually from the app settings on the device or add this bit of code to your onCreate() method.
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);
}
You'll also need to define int REQUEST_LOCATION_ENABLE_CODE as 1.
这篇关于如何修复Android BLE SCAN_FAILED_APPLICATION_REGISTRATION_FAILED错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!