Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Retrieving name and address of local Bluetooth device in Java ME

From 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
CompatibilityArticle
Created: IlGolub (19 Feb 2009)
Last edited: hamishwillee (23 Jul 2013)

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.

This page was last modified on 23 July 2013, at 07:31.
95 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×