
|
June 2004 Accessing Bluetooth from Java applications using JNI
|
|
|
In this article, we'll be presenting a sample implementation of Bluetooth communication. This Bluetooth JNI library and sample application was created by Tage Borg from the Royal Institute of Technology in Sweden with support from Martin Svensson of the Swedish Institute of Computer Science. All code is provided "as is". The Bluetooth communication code is written in C++ and is accessed from an application written in Java using JNI. The code is divided into three parts; the C++ Bluetooth library, an example Java client and an example Java server. The following zip files contain the example applications both as source code and as ready-made installation files suitable for either the P800 or P900. Running the example Make sure that Bluetooth is activated on both devices and that the device that will be acting as the server is set to "discoverable" mode ("Visible to other devices" in the case of a P900). When activated, a Bluetooth symbol should be displayed in the bottom of the screen when in "flip-open" mode and towards the top right hand corner when in "flip-closed" mode. Bluetooth can be activated using "Control panel --> Connections --> Bluetooth". Echoserver is a Java application that implements a Bluetooth server. When started, the button "Start server" should be pressed to listen for incoming connections on port 15 using Bluetooth.
Echoclient is a Java application that can perform device discovery, open a connection to any nearby device found and send text messages. When the client has been started, the "Discover" button should be pressed. This will initiate Bluetooth device discovery so that other Bluetooth devices can be found. The discovery phase may take 30 seconds or more to complete, so please have some patience. When other Bluetooth devices have been found, they will be displayed in a list, ready for you to select one. The Bluetooth device with the echoserver should be chosen. Next, the "Connect" button should be pressed, as this will open a connection between the client and the server. Finally, the "Send" button can be pressed, as this will send a text string to the server, which will be echoed back to the client. All communication is wireless and uses the short-range Bluetooth radio communication standard. Compiling the example Detailed instructions for building the examples have been provided in the file "sicsbtlib_compile_guide.txt" which is included in the zip archive. Interface to Bluetooth native methods in sicsbtlib The SicsBtLibSymbian class includes the following public methods: SicsBtLibSymbian() The BTSocket class includes the following public methods: The SDPRecord class mainly contains information about the Bluetooth connection. BTDevice represents a specific Bluetooth device. Interface usage for client application Interface usage for server application | |
Copyright © 2001 - 2009 Sony Ericsson Mobile Communications AB. All Rights Reserved.