This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why the device will connect again when we diconnect from device?

I modified the nordic uart apk from this website

github.com/.../Android-nRF-UART

and I do some revising below

MainActivity.java:
if (action.equals(WearableService.ACTION_GATT_DISCONNECTED)) {
    runOnUiThread(new Runnable() {
     public void run() {
     Log.d(tAg, "UART_DISCONNECT_MSG");
     mState = UART_PROFILE_DISCONNECTED;
     //mService.close(); <--- I comment this
     }
     });
 }

When I disconnect from device, I can see log on my phone Xperia X compact (android 7.0)

BluetoothGatt: cancelOpen() - device: F1:C1:E2:24:ED:57
BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=F1:C1:E2:24:ED:57
BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=F1:C1:E2:24:ED:57
BluetoothGatt: discoverServices() - device: F1:C1:E2:24:ED:57
BluetoothGatt: onSearchComplete() = Device=F1:C1:E2:24:ED:57 Status=0
BluetoothGatt: setCharacteristicNotification() - uuid: 6e400003-b5a3-f393-e0a9-e50e24dcca9e enable: true

I find It will connect again after I disconnect from the device and then do discoverServi

ce and finally disconnect, why???? The workaround method is uncomment the mService.close() to release the resource when MainActivity.java gets DISCONNECT broadcast.

Below is the screen shot of my phone(we only revised UUID for UartService, there are no revising at Uart apk). When I disconnect from device at 10:18:45 and then reconnect at 10:18:47 and then send one command(this device automatically notify data to apk per 3 second) and then finally disconnect.image description

Another product we develop is below, because it will reconnect, so the button still show Disconnect, not Connect, and we can't change button state anymore, because it has disconnect, we can't send disconnect command to it.image description

below is operate null pointer.image description

Parents
  • enter code here

    I BroadcastQueue: am_broadcast_finished: [background,1,Intent 
      act=android.bluetooth.adapter.action.DISCOVERY_STARTED flg=0x10 }]
    I BroadcastQueue: am_broadcast_finished: [background,1,Intent { act=null.CONNECTION_ALARMflg=0x14 (has extras) }]
    E bt_btif : bta_gattc_cache_load: can't open GATT cache file 
    /data/misc/bluetooth/gatt_cache_f1c1e224ed57 for reading, error: No such file or directory
    W SearchService: Abort, client detached.
    I ServiceManager: Waiting for service AtCmdFwd...
    E bt_btif : bta_gattc_process_indicate, ignore HID ind/notificiation
    D BtGatt.GattService: onConnected() - clientIf=6, connId=6, address=F1:C1:E2:24:ED:57
    D BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=F1:C1:E2:24:ED:57
    I UartService: Connected to GATT server.
    D BluetoothGatt: discoverServices() - device: F1:C1:E2:24:ED:57
    
Reply
  • enter code here

    I BroadcastQueue: am_broadcast_finished: [background,1,Intent 
      act=android.bluetooth.adapter.action.DISCOVERY_STARTED flg=0x10 }]
    I BroadcastQueue: am_broadcast_finished: [background,1,Intent { act=null.CONNECTION_ALARMflg=0x14 (has extras) }]
    E bt_btif : bta_gattc_cache_load: can't open GATT cache file 
    /data/misc/bluetooth/gatt_cache_f1c1e224ed57 for reading, error: No such file or directory
    W SearchService: Abort, client detached.
    I ServiceManager: Waiting for service AtCmdFwd...
    E bt_btif : bta_gattc_process_indicate, ignore HID ind/notificiation
    D BtGatt.GattService: onConnected() - clientIf=6, connId=6, address=F1:C1:E2:24:ED:57
    D BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=F1:C1:E2:24:ED:57
    I UartService: Connected to GATT server.
    D BluetoothGatt: discoverServices() - device: F1:C1:E2:24:ED:57
    
Children
No Data
Related