Я работаю над приложением Android BLE.Я сталкиваюсь с проблемой: - когда приложение пытается подключиться, устройство BluetoothProfile.STATE_DISCONNECTED
звонит каждый раз.Он подключается 1 раз в 5,6 попыток подключения, после подключения он будет звонить BluetoothProfile.STATE_DISCONNECTED
, следующие 4,5 раза.Я закрываю соединение GATT на соединение.Вот код для разъединения
public void disconnect() {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.disconnect();
}
/**
* After using a given BLE device, the app must call this method to ensure
* resources are released properly.
*/
public void close() {
if (mBluetoothGatt == null) {
return;
}
mBluetoothGatt.close();
mBluetoothGatt = null;
}
, и я вызываю эти методы в:
else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
mConnectionState = STATE_DISCONNECTED;
disconnect();
close();
Utility.dismissProgress();
Log.i(TAG, "Disconnected from GATT server.");
Intent intent = new Intent(ACTION_GATT_DISCONNECTED);
intent.putExtra("DISCONNECTED_DEVICE_ADDRESS", gatt.getDevice().getAddress());
sendBroadcast(intent);
}.
Мне нужно, чтобы каждый раз он вызывал connect.