Very simple. the only code I have is this :
final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)){
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.d(TAG,"Device "+mDevice.getName()+" Was Found");
}
}
};
but this is not called when I pair a device . why ?
Hi you need to register you broadcast receiver for following filters
ACTION_BOND_STATE_CHANGED
and then in onReceive
add them like this
if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)){
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (mDevice .getBondState() == BluetoothDevice.BOND_BONDED) {
//means device paired
}
}
Read more Here Bluetooth Device Page
int BOND_BONDED //Indicates the remote device is bonded (paired).
int BOND_BONDING //Indicates bonding (pairing) is in progress with the remote device.
int BOND_NONE //Indicates the remote device is not bonded (paired).
Edit: after last Comment
you also need to add
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
registerReceiver(mReceiver, filter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With