Get the MAC address of any Bluetooth device from your Android app

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.