Bluetooth adapter device name and MAC address in Android

Today I am going to show you how to get the bluetooth adapter device  name (if exists) and MAC address programmatically in Android.
Note that this code will not work in emulator as it does not support bluetooth. To avoid a possible exception we check if mBluetoothAdapter==null in lines 09 and 25.

/**
 * get bluetooth local device name
 * @return device name String
 */
public static String getLocalBluetoothName() {
	BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

	// if device does not support Bluetooth
	if(mBluetoothAdapter==null){
		Log.d(TAG,"device does not support bluetooth");
		return null;
	}
	
	return mBluetoothAdapter.getName();
}

/**
 * get bluetooth adapter MAC address
 * @return MAC address String
 */
public static String getBluetoothMacAddress() {
	BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

	// if device does not support Bluetooth
	if(mBluetoothAdapter==null){
		Log.d(TAG,"device does not support bluetooth");
		return null;
	}
	
	return mBluetoothAdapter.getAddress();
}

The above methods require

android.permission.BLUETOOTH

uses permissions in AndroidManifest.xml file.

Advertisements

About cmanios

programming
This entry was posted in Android, Java and tagged , , , , , , , . Bookmark the permalink.

One Response to Bluetooth adapter device name and MAC address in Android

  1. AL says:

    How does some get their OWN mac address or even UUID of their device? I find it odd for another device to know this programmatically duing pairing. The other problem is how do I know my own if other devices are present.
    Many Thanks,
    Amith.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s