Retrieving name and address of local Bluetooth device in Java ME
This code example demonstrates how to get the name and address of a local Bluetooth device by referencing the LocalDevice object.
Article Metadata
Code Example
Source file: Media:BTLocalNameAddressSource.zip
Installation file: Media:BTLocalNameAddressBinaries.zip
Tested with
Devices(s): Nokia N85, Nokia 5800 XpressMusic, Nokia 2630, Nokia 6131, Nokia 701, Nokia Asha 305
Compatibility
Platform(s): Series 40, Symbian
Article
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) {
printString(ex.toString());
}
}
Postconditions
After starting the MIDlet, run the 'Execute snippet' command to display the name and address of the local Bluetooth device.


(no comments yet)