Recently do an Android application, with Bluetooth signal control an instrument, through a Bluetooth to the serial port device, send Bluetooth signal, and then converted to serial command sent to the instrument. The Bluetooth device is as follows:
How do I get this Bluetooth device when I write Java code in an Android app? The Bluetoothadapter Getremotedevice method can be used to obtain a Bluetooth device from a MAC address:
Bluetoothdevice device = Mbluetoothadapter.getremotedevice (address);
But the question is, how much is the MAC address of this Bluetooth device?
For mobile phones, you can view the Bluetooth address of this computer in the status message module:
However, this device for Bluetooth to the serial port, want to know its MAC address is not so easy, how to do?
Accidentally found that the Bluetooth module in Android, there is a function to obtain the saved Bluetooth device, if the Bluetooth to the serial port device and the phone to match and save, it is not possible to remove it from the Save list to get the MAC address it?
So, first use mobile phone Bluetooth and this device to match, its name is bc04-b:
Then, in the Java code:
Gets the device information that has been saved set<bluetoothdevice> devices = Mbluetoothadapter.getbondeddevices (); if (Devices.size () >0) { For (iterator<bluetoothdevice> iterator=devices.iterator (); Iterator.hasnext ();) { Bluetoothdevice Bluetoothdevice= (Bluetoothdevice) Iterator.next (); SYSTEM.OUT.PRINTLN ("Device:" +bluetoothdevice.getname () + "" + bluetoothdevice.getaddress ()); } }
Sure enough, the list of saved Bluetooth devices has been printed out in LogCat with their respective MAC addresses:
Get the MAC address of any Bluetooth device from your Android app