Archived:Retrieving the Bluetooth friendly name of a remote device using Java ME (Known Issue)
This article explains how to get the Bluetooth friendly name of a remote device using Java ME on S40 and Series 40 2nd Edition.
Article Metadata
Code Example
Tested with
Compatibility
Series 40 3rd Edition
Article
Description
In order to retrieve the friendly name of a remote device, an application must call the RemoteDevice.getFriendlyName() method, passing either "true" or "false". Using "false", the implementation will first look for a friendly name for that particular device in its cache. If one cannot be found, the remote device will be contacted and requested a friendly name. Using "true" as the parameter, no cache search will be performed, and the remote device will always be contacted for a friendly name.
In Series 40 2nd Edition devices, calling RemoteDevice.getFriendlyName() during device discovery or service search will throw a java.io.IOException every time. It is not possible to retrieve the friendly name.
To test this issue:
- Download the Devicediscovery.zip application.
- Install it to your Series 40 2nd Edition device using OTA download or PC Suite.
- Run the DeviceDiscovery application. Choose the "Disc60" command option, and the application will try to retrieve friendly names for the devices while the device discovery process is still running. This will throw java.io.IOException in all cases.
A workaround for this problem is to do as follows:
- First, retrieve all RemoteDevice objects and place them in a holder, such as a Vector.
- When DiscoveryListener.inquiryCompleted() is called by the framework, the application can then traverse the Vector and call getFriendlyName() for each device in order to retrieve its friendly name and display it.
- The "Disc40" command option of the DeviceDiscovery application uses this workaround to provide a viable way of retrieving the friendly name of the discovered devices.
Note that there is also another workaround demonstrated in the DiscoverConnect example that is part of the "Games Over Bluetooth: Recommendations To Game Developers" document. The remote devices themselves take care of informing their friendly names to the device running device/service discovery. As this functionality has to be written into the application logic, it means in practice that you need to run the same application in both ends. You cannot find out the friendly names of devices not running the MIDlet. However, this might be a useful approach in multiplayer games.
Solution
In Series 40 3rd Edition and S60 platform (all editions), calling RemoteDevice.getFriendlyName() during discovery or search returns the correct result. Note, however, that this call may also throw java.io.IOException in these platforms, but in this case throwing the exception is proper behavior because it means that the remote device could not be contacted.


(no comments yet)