2
votes

I would like to make my android app detect if a Bluetooth headset (either by name or mac address) is connected and then run code based on whether it is connected or not. The problem is I've been hitting a brick wall in regards to how to get the name/mac address of the currently connected Bluetooth headset.

The following code simply gives me the hostname of the Android device:

  BA = BluetoothAdapter.getDefaultAdapter();
  String name = BA.getName();

When I used "getBondedDevices()", it usually just gives me the devices that the phone has been paired to, but not actually what is connected at the moment. In other words, it gives me the list of previously paired devices, but not the actual connected device.

I have no clue as to what I'm doing because this is the first time dealing with Bluetooth devices and the Google's developer site is great about telling what BluetoothDevice is capable of, but not necessarily of examples of how to use it.

So can someone please give me some helpful code that could get the name/mac address of the current connected bluetooth handset. Thanks in advance for any and all help

1
I am also facing same issue. Have you got any soluction?GNK

1 Answers

0
votes

Once you re making a bluetooth connection that time you can save the connected device information(name and address) in shared preferences and get it when you want to get connected device info.