0

First of all, my English is very poor.

I am developing an Android Application that connects to a BLE Device and reads the specific GATT Characteristics and Services that I need to check. I used the BluetoothLeGATT example from the Android Dev site as my reference. I can connect to a predefined Address without problems and read the GATT Attribute updates.

Next, I would like to design an automatic connection device and read the function of the device data.

Following:

1.Automatic scanning, the device will be stored in DeviceList;

2.Connect(mBluetoothGatt.connect()) the device to the DeviceList sequence and read the data,then disconnect(mBluetoothGatt.disconnect()),finally,close( mBluetoothGatt.close());

3.Ten minutes after the interval to repeat the second step;

Result: A few times before the connection is not any problem.

Then there will be such a problem:I only called once Connect(mBluetoothGatt.connect()),but BluetoothGattCallback.onConnectionStateChange() will be called many times.

So will appear repeatedly called connected and disconnected.

Then there will be a Device called disconnect, but did not cancel the pairing.

How can I solve?

  • I think this is a problem of BLE nature, many Bluetooth LE devices is a pure Peripheral device, it is not possible to use it to connect. I do not think it is your software but mostly your hardware nature. And btw bluetooth device is not the same as bluetooth LE – Maytham Fahmi Mar 28 '16 at 07:31
  • I use Android as the Center device,many BLE deivce as Peripheral device.All operations are carried out on the Android phone.I would like to know, why only a connection, there will be a number of BluetoothGattCallback.onConnectionStateChange() is called?Of course, I also found that the change of clientIf will make BluetoothGattCallback.onConnectionStateChange() called, so I want to know why there will be a connection in the process will have a number of clientIf is changed – MingJude Wang Mar 29 '16 at 02:02
  • Do you set the autoconnect boolean to true in the BluetoothGatt.connect() call? – p2pkit Mar 30 '16 at 06:54
  • Possible duplicate of [How to prevent BluetoothGattCallback from being executed multiple times at a time](https://stackoverflow.com/questions/33274009/how-to-prevent-bluetoothgattcallback-from-being-executed-multiple-times-at-a-tim) – James Allen Apr 05 '18 at 08:59

0 Answers0