0
votes

I was working with a BLE device, which needs to set the device time during pairing. Writing to the time characteristic in any other time does not effectively set the time.

Currently I am using the Android OS's Bluetooth Manager for pairing. And the progress of pairing is notified to my app through broadcast intent.

public void onReceive(Context context, Intent intent) {
    ....
    switch (action) {
    case BluetoothDevice.ACTION_BOND_STATE_CHANGED: 
        if(state == BluetoothDevice.BOND_BONDED){
            //Write to the Date-Time Characteristic
        }
        else if(state==BluetoothDevice.BOND_BONDING){
        }
        else if(state==BluetoothDevice.BONE_NONE){
        }
     ....
     }
     ...
    }

My question is how to inject code to the position commented above to complete the Date-Time setting? Apparently, the Android OS Bluetooth Manager does not set the time during its entire pairing process. Does Android allow two applications (OS Bluetooth Manager and my application) write to the remote gatt within a single connection session?

1

1 Answers

1
votes

It may not possible for you to write the data-time i.e. the characteristic during the pairing procedure(well if you do not need pairing that should be fine). Reason is that you may first get service and get characteristic handle then write it, this may not happen with the same time of the pairing; it depends your remote device's security level setting.

My question is how to inject code to the position commented above to complete the Date-Time setting?

You can register a broadcast receiver to receive the bonding event.

Does Android allow two applications (OS Bluetooth Manager and my application) write to the remote gatt within a single connection session?

Sure, because you are using the same BluetoothAdapter :-)