我有一个Android应用程序,用于连接蓝牙低功耗(BLE)和我的手机.该应用程序在Galaxy S5(Android 5.0.1),Galaxy S6(Android 6.0)等近乎手机中运行良好.但是,它在Galaxy Note 3(Android 5.0.1)中存在一个关键问题.
当我调用该connect()函数,然后调用readCharacteristic()它时,它返回错误:
onClientConnectionState() - status = 22 clientIf = 7
我调用connect函数约2秒后发生错误.我查找了一些解决方案,比如在通话前做出延迟 readCharacteristic(),但是无法解决.
你能解决我的问题吗?
谢谢大家.
这是我的代码:
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
mBluetoothGatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
try {
Thread.sleep(500);
readCharacteristic(); …Run Code Online (Sandbox Code Playgroud) 我有一个从IntentService调用的BluetoothLeService.BLEService工作正常,直到它连接.在与iBeacon建立连接后,它会调用;
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction);
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都还可以,但在此之后,尽管mBluetoothGatt.discoverServices()返回true,但从不调用onServicesDiscovered(BluetoothGatt gatt,int status).
--------------------- UPDATE ---------------------------- ------
在调试时它显示newState == BluetoothProfile.STATE_CONNECTED但它没有真正连接.对于属于未使用设备的假id,它显示相同的结果.
-------------------------------------------------- -----------
这是我的回调
private …Run Code Online (Sandbox Code Playgroud)