大多数时候它工作得很好,但有时我在尝试发现 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
错误代码2代表https://developer.android.com/reference/android/bluetooth/le/ScanCallback.html#SCAN_FAILED_APPLICATION_REGISTRATION_FAILED https://developer.android.com/reference/android/bluetooth/le/ScanCallback.html#SCAN_FAILED_APPLICATION_REGISTRATION_FAILED
这似乎是 Android 内部问题,但它可能会受到我的代码做错事的影响。原因是什么以及如何解决它?
附言。 Nexus 9,安卓 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" />
您必须打开应用程序的“精细位置”或“粗略位置”权限。
您可以从设备上的应用程序设置手动执行此操作,或将这段代码添加到 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。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)