Namespaces
Variants
Actions

Retrieving name and address of local Bluetooth device in Java ME

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 Example
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 (17 Jun 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 17 June 2013, at 07:09.
212 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved