0

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!

Fábio Nascimento
  • 2,644
  • 1
  • 21
  • 27
MarioCas
  • 29
  • 5
  • Do you have all of AndroidManifest.xml permissions? https://stackoverflow.com/questions/33045581/location-needs-to-be-enabled-for-bluetooth-low-energy-scanning-on-android-6-0 Since Android 6.0 location needs to be enabled. If you are starting youur journey with Bluetooth on Android, I suggest to use some reliable library to ease your tasks. https://android-arsenal.com/tag/134?sort=created – Lukas Feb 27 '19 at 12:44
  • I used this: – MarioCas Feb 27 '19 at 12:57
  • Can you please specify what you mean with "my app doesn't work"? Does it crash? Do you get any errors? Is there any particular thing that you think should happen that never happens? – Emil Feb 27 '19 at 18:55
  • When it finds the devices, I click Connect and enter the command page to turn on/off the device... But it is disconnected and I can not turn on/off the LEDs. This does this using pairing. If I don't use anything everything works perfectly. – MarioCas Feb 28 '19 at 08:59
  • The device not works when her pairs with my phone – MarioCas Feb 28 '19 at 09:57
  • Texas Instruments had a bug in their BLE chip that did not ignore the new flag 'secure pairing' supported. Since Android supported this new secure connections in Android 6 and up no TI chip with this bug could bond with the Android. The TI chip aborted the attempt. If this is indeed the case, it will pair on 4 and 5 and die on 6. If no pairing, it will work fine – Brian Reinhold Sep 08 '20 at 23:12

0 Answers0