I'm working with my device of Texas Instruments and I create the my custom APP. I searching the problems with pairing and bonding in Android Studio. If I disable the pairing in my device, the my app it works, instead, if I enable the pairing in my device, the my app doesn't works.
I'm new in Android Studio and I haven't implement nothing in my code of pairing and bonding.
I try this a part of code in scannerCallBack
of MainActivity
:
if (btDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
Log.d(TAG, "onScanResult: Bonded");
btDevice.createBond();
}
Then I tried to make this in BroadcastReceiver
of SelectedDeviceActivity
:
if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED))
{
final int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
switch(state){
case BluetoothDevice.BOND_BONDING:
// Bonding...
break;
case BluetoothDevice.BOND_BONDED:
// Bonded...
mActivity.unregisterReceiver(mReceiver);
break;
case BluetoothDevice.BOND_NONE:
// Not bonded...
break;
}
}
Please help me, because I don't know how to resolve this problem.
Thanks!