Android Bluetooth Low Energy Pairing -


how pair bluetooth low energy(ble) device android read encrypted data.

using information in android ble page, able discover device, connect it, discover services , read un-encrypted characteristics.

when try read encrypted characteristic (one cause ios show popup asking pair , complete read) getting error code 5, corresponds insufficient authentication.

i not sure how device paired or how provide authentication information read complete.

i toyed bluetoothgattcharacteristics trying add descriptors, did not work either.
appreciated!

when gatt_insufficient_authentication error, system starts bonding process you. in example below i'm trying enable notifications , indications on glucose monitor. first i'm enabling notifications on glucose measurement characteristic can cause error appear.

@override     public void ondescriptorwrite(bluetoothgatt gatt, bluetoothgattdescriptor descriptor, int status) {         if (status == bluetoothgatt.gatt_success) {             if (gm_characteristic.equals(descriptor.getcharacteristic().getuuid())) {                 mcallbacks.onglucosemeasurementnotificationenabled();                  if (mglucosemeasurementcontextcharacteristic != null) {                     enableglucosemeasurementcontextnotification(gatt);                 } else {                     enablerecordaccesscontrolpointindication(gatt);                 }             }              if (gm_context_characteristic.equals(descriptor.getcharacteristic().getuuid())) {                 mcallbacks.onglucosemeasurementcontextnotificationenabled();                 enablerecordaccesscontrolpointindication(gatt);             }              if (racp_characteristic.equals(descriptor.getcharacteristic().getuuid())) {                 mcallbacks.onrecordaccesscontrolpointindicationsenabled();             }         } else if (status == bluetoothgatt.gatt_insufficient_authentication) {             // tricky part comes              if (gatt.getdevice().getbondstate() == bluetoothdevice.bond_none) {                 mcallbacks.onbondingrequired();                  // i'm starting broadcast receiver listen bonding process changes                  final intentfilter filter = new intentfilter(bluetoothdevice.action_bond_state_changed);                 mcontext.registerreceiver(mbondingbroadcastreceiver, filter);             } else {                 // situation happens when try connect second time bonded device                 // should never happen, in opinion                 logger.e(tag, "the phone trying read paired device without encryption. android bug?");                 // don't know here                 // error found on nexus 7 krt16s build of andorid 4.4. not appear on samsung s4 andorid 4.3.             }         } else {             mcallbacks.onerror(error_write_descriptor, status);         }     }; 

where mbondingbroadcastreceiver is:

private broadcastreceiver mbondingbroadcastreceiver = new broadcastreceiver() {     @override     public void onreceive(final context context, final intent intent) {         final bluetoothdevice device = intent.getparcelableextra(bluetoothdevice.extra_device);         final int bondstate = intent.getintextra(bluetoothdevice.extra_bond_state, -1);         final int previousbondstate = intent.getintextra(bluetoothdevice.extra_previous_bond_state, -1);          logger.d(tag, "bond state changed for: " + device.getaddress() + " new state: " + bondstate + " previous: " + previousbondstate);          // skip other devices         if (!device.getaddress().equals(mbluetoothgatt.getdevice().getaddress()))             return;          if (bondstate == bluetoothdevice.bond_bonded) {             // continue you've started before             enableglucosemeasurementnotification(mbluetoothgatt);              mcontext.unregisterreceiver(this);             mcallbacks.onbonded();         }     } }; 

remember unregister broadcast receiver when exiting activity. may have not been unregistered receicver itself.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -