Revision as of 09:58, 15 October 2012 by hamishwillee (Talk | contribs)

Retrieving name and address of local Bluetooth device in Java ME

From Nokia Developer Wiki
Jump to: navigation, search

This code example demonstrates how to get the name and address of a local Bluetooth device by referencing the LocalDevice object.

Article Metadata
Code ExampleTested with
Devices(s): Nokia N85, Nokia 5800 XpressMusic, Nokia 2630, Nokia 6131, Nokia 701, Nokia Asha 305
Keywords: javax.bluetooth.LocalDevice, javax.bluetooth.BluetoothStateException
Created: IlGolub (19 Feb 2009)
Last edited: hamishwillee (15 Oct 2012)

Source file: BTLocalNameAddress.java

import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.LocalDevice;
* Executes the snippet.
* Implementation retrieves the local device bluetooth name and address and
* prints it out to log TextField.

private void executeSnippet() {
try {
//Object of LocalDevice type provides some
//functions of the Bluetooth manager.
//we get it through the static method getLocalDevice()
LocalDevice localDevice = LocalDevice.getLocalDevice();
//through the getFriendlyName() method we can get the
//name of the local bluetooth device.
//The Bluetooth specification calls this name the
//"Bluetooth device name" or the "user-friendly name".
String localDeviceName = localDevice.getFriendlyName();
printString("Local device name: " + localDeviceName);
//through the getBluetoothAddress() method we can get the
//adress of the local bluetooth device
String localDeviceAdress = localDevice.getBluetoothAddress();
printString("Local device adress: " + localDeviceAdress);
} catch (BluetoothStateException ex) {


After starting the MIDlet, run the 'Execute snippet' command to display the name and address of the local Bluetooth device.

82 page views in the last 30 days.