Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Bluetooth - createBond return value

I am working on a Bluetooth application. It consists, among other things, of a list view displaying the paired and visible devices. Long clicking on the unpaired ones opens up the pairing dialog which I have implemented using this code-

Class class1 = Class.forName("android.bluetooth.BluetoothDevice");  
Method createBondMethod = class1.getMethod("createBond");   
int position = ((AdapterContextMenuInfo)item.getMenuInfo()).position;
boolean result = ((Boolean)createBondMethod.invoke(pairedDevices.get(position).getDevice())).booleanValue();

I have observed that this method returns immediately without waiting for the pairing to complete. But I need to know whether the pairing succeeded or not. Is this indicated in the function's return value or is there some other way of knowing it ?

Thanks in advance,

like image 733
Cygnus Avatar asked Sep 25 '26 00:09

Cygnus


1 Answers

From the documentation:

Start the bonding (pairing) process with the remote device.

This is an asynchronous call, it will return immediately. Register for ACTION_BOND_STATE_CHANGED intents to be notified when the bonding process completes, and its result.

like image 191
Lucas Zamboulis Avatar answered Sep 26 '26 16:09

Lucas Zamboulis