简体   繁体   中英

How do I get the name of the current connected bluetooth device?

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

一旦建立了蓝牙连接,您就可以将连接的设备信息(名称和地址)保存在共享首选项中,并在需要获取连接的设备信息时获取。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM