Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unpair or delete paired bluetooth device programmatically on android?

The project is to use my android phone to connect with my arduino devices. but how can I unpair the paired ones. I see it seems the paired list is stored where bluetoothadapter could retrieve anytime.

PS: 1st, I know long press paired device will unpair it.
but the question here is how can I make this happen programmatically?

2nd, I have checked bluetoothdevice and bluetoothAdapter class, there is no function to implement this.

thanks.

like image 914
Dev Perfecular Avatar asked Mar 07 '12 19:03

Dev Perfecular


People also ask

How do you Unpair Bluetooth device programmatically in Android?

Using Android Bluetooth API, we can use createBond method to pair with a device or removeBond to unpair. This is an asynchronous call so that it will return immediately. To catch the pairing process, we have to register a BroadcastReceiver with ACTION_BOND_STATE_CHANGED intent to catch the process.

How do I Turn Off Bluetooth pairing on my Android phone?

1 From a Home screen, do one of the following: Ensure Bluetooth is turned on. Navigate: Settings > Connected devices > Connection preferences > Bluetooth. Navigate: Settings > Connected devices. ... 2 Tap the appropriate device name or the Settings icon (right). 3 Tap 'Forget' or 'Unpair'.

How do I forget or unpair a Bluetooth device?

Navigate: Settings > Connected devices > Connection preferences > Bluetooth. Navigate: Settings > Connected devices. If necessary, tap Bluetooth. Navigate: Settings > Bluetooth. Tap the appropriate device name or the Settings icon (right). Tap 'Forget' or 'Unpair'.

How do I unpair my Device from my phone?

1 Open the Settings 2 Tap on Connections 3 Tap on Bluetooth 4 Open the Settings of paired device 5 Tap on Unpair

How to unpair or remove bonding for paired device in Android?

I have requirement to unpair or remove bonding for paired device. Could not find any API to unpair device in Android.Bluetooth->BluetoothDevice. Using Android Bluetooth API, we can use createBond method to pair with a device or removeBond to unpair. This is an asynchronous call so that it will return immediately.


1 Answers

This code works for me.

private void pairDevice(BluetoothDevice device) {     try {         if (D)             Log.d(TAG, "Start Pairing...");          waitingForBonding = true;          Method m = device.getClass()             .getMethod("createBond", (Class[]) null);         m.invoke(device, (Object[]) null);          if (D)             Log.d(TAG, "Pairing finished.");     } catch (Exception e) {         Log.e(TAG, e.getMessage());     } }  private void unpairDevice(BluetoothDevice device) {     try {         Method m = device.getClass()             .getMethod("removeBond", (Class[]) null);         m.invoke(device, (Object[]) null);     } catch (Exception e) {         Log.e(TAG, e.getMessage());     } } 
like image 123
Dev Perfecular Avatar answered Sep 23 '22 20:09

Dev Perfecular