Using Bluetooth stack in desktop application
I tried to find information about developing desktop applications with Bluetooth support using Java but it seems that most of the articles are concentrated in mobile J2ME implementations. Now that I wanted to develop desktop bluetooth application I thought that I’d write down how I managed to do so. Read on, if you are interested…

Step 1. Find Bluetooth Stack Implementation for J2SE
There aren’t many JSR-82 implementations available for the desktop environment. Most of them are commercial but I was able to find the open source version from www.javabluetooth.org. So the first thing was to download the source code and try to compile it. It wouldn’t compile as it depended on the Java Communications API (javax.comm.*). After I had downloaded the comm library I added comm.jar to my class path and I was able to compile the JavaBluetooth library. You can download the compiled binary here.
But… It turned out that JavaBluetooth library only supports Bluetooth devices with serial connection and thus it didn’t work with my laptop that has a built-in Bluetooth adapter.
This led me to another great site, www.javabluetooth.com, which has a small list of Java Bluetooth SDKs and it included a library called BlueCove. This library works only on Windows platform but it will do for now as there aren’t other free options to choose from.
Step 2. Hello Bluetooth World
Next thing was to try it out by coding a simple application that would sniff any nearby bluetooth devices using the laptops built-in bluetooth adapter. This was easier then I thought.
You have to create class that will implement DiscoveryListener interface and the use DiscoveryAgent to search for devices. You can get the discovery agent from LocalDevice object as seen in the following code sample:
public class BluetoothBrowser
implements DiscoveryListener {
private LocalDevice localDevice;
private DiscoveryAgent agent;
/** Creates a new instance of BluetoothBrowser */
public BluetoothBrowser()
throws BluetoothStateException {
localDevice = LocalDevice.getLocalDevice();
agent = localDevice.getDiscoveryAgent();
}
/** Start inquiry */
public void inquiry()
throws BluetoothStateException {
agent.startInquiry(DiscoveryAgent.GIAC, this);
}
...implementations for DiscoveryListener...
Step 3. Done
You can download the source code from here. The package also includes project files for the NetBeans IDE 6.0 M10.So this should get you started… I’ll might write more about using Bluetooth with desktop applications in the future posts.
July 22nd, 2007 at 15:29
Thanks for this wonderfull support. i’m having a problem in running this application as m not much good in java.
The other thing is that i want to send images from my PC to several mobile phones at a time. As my goal is to advertise in a shopping mall by creating a bluetooth network. if u can help me in my project so i’l be very thankfull to you. i don have much time left because i hv to submit my project in a month. so please if you have anything that can help me so plz do mail me.
Thanking You
Regards,
Romail
July 22nd, 2007 at 16:00
Hi,
I try this code but i am getting Error as below….
I am getting Blue tooth Stack is not intialized.. i dont know how to slove this problem. Plz can u help me !!
Output (Error):
LOG: Start discovery
class.getName() javax.bluetooth.LocalDevice
localDevicejavax.bluetooth.LocalDevice
error BluetoothStack not detected
com.intel.bluetooth.BlueCoveImpl.(BlueCoveImpl.java:136)
Exception in thread “AWT-EventQueue-0″ java.lang.ExceptionInInitializerError
at com.intel.bluetooth.BlueCoveImpl.instance(BlueCoveImpl.java:195)
at javax.bluetooth.LocalDevice.(LocalDevice.java:65)
at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:80)
at com.substanceofcode.bluetooth.BluetoothBrowser.(BluetoothBrowser.java:43)
at com.substanceofcode.presence.Controller$1.run(Controller.java:45)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.lang.RuntimeException: BluetoothStack not detected
at com.intel.bluetooth.BlueCoveImpl.(BlueCoveImpl.java:137)
at com.intel.bluetooth.BlueCoveImpl.(BlueCoveImpl.java:35)
at com.intel.bluetooth.BlueCoveImpl$SingletonHolder.(BlueCoveImpl.java:82)
… 12 more
Thanks & Regards
M.S.HariKumar
July 22nd, 2007 at 23:28
HariKumar:
The error message seems to indicate that it didn’t recognize the local bluetooth device. What adapter are you using? USB? Integrated?
Romail:
I understand what you are trying to achieve but I don’t have experience either on developing that kind of a service. I suppose that it could be implemented so that the server would scan the surrounding devices like every 10 seconds and if it finds any new devices it would then try to send an image to the client. I assume that you are able to send a file to one phone at once or maybe when you’d had several bluetooth adapters then you could do parallel transmissions with each adapter. I’d be very interested in seeing your code if you are willing to share it?
August 10th, 2007 at 13:35
Superb! A good article. Simple yet understandable. Cheers, Wyell
August 16th, 2007 at 09:51
hi ,
I am trying to connect pc-pc through bluetooth and J2se .
U r program provide me wonderful support but I have another problem that How I find Address of other connected device ?
plz , help my.
Thanks
August 19th, 2007 at 22:46
Hi Tommi,
im still unable to achieve my goal, please if u have any solutions please do mail me. pleaseeeeeeee….
Best Regards
Romail
August 20th, 2007 at 22:47
Hi Tommi,
Thanks for your reply.
Just to remind you that my project scenario is to develop a software which can send images from a PC to several mobile phones concurrently through bluetooth. i need to develop it on J2SE.
I send u the code twice but both the time i got delivery failure…
My code need a plug n play bluetooth usb dongle but m using a driver one. second thing is that this code only send to single device but i hv to send it to multiple device concurrently. if you can help me il be very thankful to you.
Best Regards,
Romail
August 23rd, 2007 at 05:40
hi ,
Tommy sir ,
I solve my problem myself .
bye.
August 23rd, 2007 at 07:47
Arifa: That is great! Would you like to tell how you did it?
August 25th, 2007 at 08:58
hi,
i’m trying to develop a bluetooth application,but the first thing i need is the javax.bluetooth library or more specifically the jsr-82 implementation.i’ve tried hard to get it but i can’t get it.so plzzz arifa can u u tell me where u got urs?
i’m hanging on ur words,reply soon
August 25th, 2007 at 09:22
Quratulain: You should get the JSR-82 implementation from http://www.javabluetooth.org/ atleast if you are targeting for the Windows platform. You should be able to find more implementations using the google search: http://www.google.fi/search?q=jsr-82+implementation+download
August 25th, 2007 at 09:27
thanx a lot sir!
i’ll check them out and i daresay,again!
August 27th, 2007 at 12:38
Sure,
In BluetoothBrowser.java
public void deviceDiscovered(RemoteDevice device, DeviceClass devClass) {
try {
Log.add(”Device discovered Name: ” + device.getFriendlyName(false));
Log.add(”Device discovered Address: ” + device.getBluetoothAddress());
} catch (IOException ex) {
Logger.getLogger(”global”).log(Level.SEVERE, null, ex);
}
}
September 5th, 2007 at 00:59
Dear Tommy, I follow the steps but I getting de same error that HariKumar. I using USB adapter and test the code under Linux platform and Windows but its the same error. Its very important, thanks.
September 5th, 2007 at 23:44
Richard, the BlueCove driver only works with Windows XP SP2 and above. But as it says in the BlueCove’s project page it should also support Linux in upcoming releases: http://code.google.com/p/bluecove/
September 6th, 2007 at 14:33
Thank you for your answer, yesterday searching information about the error I found a jsr-82 implementation that works under Linux y its wonderful. But thank to your comments and the rest of the people I could clear several doubts about how develop desktop applications with Bluetooth support using Java Standard Edition.
September 7th, 2007 at 07:53
Richard: Would you be willing to share what driver did you find for the Linux platform? Does anyone know any multi platform drivers that are free to use?
September 7th, 2007 at 15:33
Sure, http://sourceforge.net/projects/avetanabt/ from here can you download de jsr-82 implementation, under Linux platform its free to use but in Windows and Mac OS don’t. http://sourceforge.net/project/showfiles.php?group_id=176926&package_id=206506 here can you download an example of the implementation, its very simple to use and with that the only limitation for the desktop applications with Bluetooth support using J2SE it the programmer imagination. This is the home page of Avetana
http://www.avetana-gmbh.de/avetana-gmbh/produkte/jsr82.eng.xml and the API’s can you download from here http://www.avetana-gmbh.de/avetana-gmbh/produkte/doc.tgz. I hope that it is useful for you and the rest of the people. Any doubts just ask and don’t forget of sharing because is the essence of the community.
September 12th, 2007 at 00:25
Hi Tommy!
very good example to read here. i have got to do the same kind of job so requesting for your help. . . i have to develop a software which will send a mobile application to the mobile phones from PC using bluetooth so later on the mobile phones could use that application (also to as many mobile phones at a time as they come into bluetooth range). can you please guide me where i have to start from to get this finished asap coz i’ve got v short time. thanks and waiting for your thoughtful reply.
regards
Muhammad.
September 13th, 2007 at 16:26
Hello! I have problem: my IO:
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:15: package javax.bluetooth does not exist
import javax.bluetooth.BluetoothStateException;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:16: package javax.bluetooth does not exist
import javax.bluetooth.DeviceClass;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:17: package javax.bluetooth does not exist
import javax.bluetooth.DiscoveryAgent;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:18: package javax.bluetooth does not exist
import javax.bluetooth.DiscoveryListener;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:19: package javax.bluetooth does not exist
import javax.bluetooth.LocalDevice;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:20: package javax.bluetooth does not exist
import javax.bluetooth.RemoteDevice;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:21: package javax.bluetooth does not exist
import javax.bluetooth.ServiceRecord;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:27: cannot find symbol
symbol: class DiscoveryListener
public class BluetoothBrowser implements DiscoveryListener {
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:29: cannot find symbol
symbol : class LocalDevice
location: class com.substanceofcode.bluetooth.BluetoothBrowser
private LocalDevice localDevice;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:30: cannot find symbol
symbol : class DiscoveryAgent
location: class com.substanceofcode.bluetooth.BluetoothBrowser
private DiscoveryAgent agent;
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:33: cannot find symbol
symbol : class BluetoothStateException
location: class com.substanceofcode.bluetooth.BluetoothBrowser
public BluetoothBrowser() throws BluetoothStateException {
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:38: cannot find symbol
symbol : class BluetoothStateException
location: class com.substanceofcode.bluetooth.BluetoothBrowser
public void inquiry() throws BluetoothStateException {
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:42: cannot find symbol
symbol : class RemoteDevice
location: class com.substanceofcode.bluetooth.BluetoothBrowser
public void deviceDiscovered(RemoteDevice device, DeviceClass devClass) {
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:42: cannot find symbol
symbol : class DeviceClass
location: class com.substanceofcode.bluetooth.BluetoothBrowser
public void deviceDiscovered(RemoteDevice device, DeviceClass devClass) {
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:50: cannot find symbol
symbol : class ServiceRecord
location: class com.substanceofcode.bluetooth.BluetoothBrowser
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:34: cannot find symbol
symbol : variable LocalDevice
location: class com.substanceofcode.bluetooth.BluetoothBrowser
localDevice = LocalDevice.getLocalDevice();
C:\Documents and Settings\Root\Pulpit\java\bluetoothpresence\src\com\substanceofcode\bluetooth\BluetoothBrowser.java:39: cannot find symbol
symbol : variable DiscoveryAgent
location: class com.substanceofcode.bluetooth.BluetoothBrowser
agent.startInquiry(DiscoveryAgent.GIAC, this);
17 errors
BUILD FAILED (total time: 3 seconds)
What i must do????
September 14th, 2007 at 13:37
ur code doesn’t work.
localDevice = LocalDevice.getLocalDevice(); ==> return null
I tried to follow that line with:
System.out.println(localDevice.getBluetoothAddress()); ==> result: 000000000000
FYI, I’m using desktop pc with usb dongle from IVT corporation bluesoleil.
The driver is version 1.4 I think.
I’m already using XP SP2.
Why the code doesn’t work?
September 14th, 2007 at 13:43
Hi Alex! What JSR-82 implementation are you using? Are you using the BlueCove library that I mentioned in this entry or some other implementation?
September 14th, 2007 at 14:13
yes, it is. I’m using bluecove-2.0.1.jar
any idea Tom?
September 14th, 2007 at 14:22
Alex, you could try out using other implementations like Avetana, BlueSock or ElectricBlue.
September 14th, 2007 at 16:50
Tom, I still cannot do the following code:
LocalDevice localDevice = LocalDevice.getLocalDevice();
with all those implementations. I dunno why but BlueSock and ElectricBlue always generate a runtime exception.
Is there anything I should write before that line?
September 14th, 2007 at 18:23
I’ve tried all those implementations but still cannot do the following code:
LocalDevice device = LocalDevice.getLocalDevice();
It will produce a runtime exception with BlueSock and ElectricBlue library, while BlueCove did not produce any error but return null.
dunno why. Has it something to do with my bluetooth driver? Or should I put some code before that line?
September 14th, 2007 at 23:07
Hello Alex, one question: what kind of bluetooth device you have connected to your PC?
September 14th, 2007 at 23:14
I forgot!!!, Tommy you have any idea how can I get all the local devices connected? In my desktop application I have to use several local devices and I don’t know how get all of them.
Thanks.
September 15th, 2007 at 02:42
I’m using desktop pc with USB dongle from IVT corporation bluesoleil.
The driver is version 1.4 I think.
Looking forward to your suggestion Richard
September 16th, 2007 at 03:28
Hi Tom,
Im from Mexico and I very interesting to make an application can send images to other devices with Bluetooth. But Im kind stuck rigth now cu’z when I use this code:
try {
System.out.println(”Entramos”);
localDevice = LocalDevice.getLocalDevice();
}
catch(BluetoothStateException e) {
e.printStackTrace();
System.out.println(”Error al iniciar”+” el sistema Bluetooth” + e.getLocalizedMessage());
return;
}
Give me the follow exception:
javax.bluetooth.BluetoothStateException
at com.sun.kvem.jsr082.bluetooth.LocalDeviceImpl.(LocalDeviceImpl.java:185)
at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:94)
at ClientBluetooth.inicioo(ClientBluetooth.java:13)
at ClientBluetooth.main(ClientBluetooth.java:32)
I’m using jsr82.jar and usb bluetooth dungle.
Thanks.
Luis Fernando
September 17th, 2007 at 16:50
Alex try this, test the code with other bluetooth device. If you installed the software that come with the device, uninstall this and let that windows install the driver. After that try again.
September 27th, 2007 at 17:11
Hi there, thank you very much for your code example. I have a problem with it however. I am also trying to connect my mobile phone to PC for data transfer. Your code along with bluecove stack manages to find my mobile phone. However, for programming purposes, I would like it to also detect netbeans emulated mobile phones but it does not.
Do I need any specific bluetooth code on the mobile end of things for it to be simply detected? I simply want to send some bits and bites from phone to PC but it is such a burden trying to find examples. Your code is the closest I have come to what I need. Thanks alot.
October 4th, 2007 at 05:32
It worked!! Thx Richard!!
October 5th, 2007 at 13:15
Hi, first I need to say, that this is a real great explanation of the Java Bluetooth Api. Yesterday I tried to use the bluecove stack and wrote the following program. Unfortunatelly, when I executed the program in Eclipse, the search was finished after some seconds without finding any other bluetooth devices. Does anybody knows the reason therefore?
public class Blue implements DiscoveryListener {
public Blue(){
try {
LocalDevice local = LocalDevice.getLocalDevice();
DiscoveryAgent ag = local.getDiscoveryAgent();
ag.startInquiry(DiscoveryAgent.GIAC, this);
} catch (BluetoothStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Blue b = new Blue();
}
public void deviceDiscovered(RemoteDevice d, DeviceClass arg1) {
// TODO Auto-generated method stub
System.out.println(”Device ” + d.getBluetoothAddress() + ” discovered”);
}
public void inquiryCompleted(int arg0) {
// TODO Auto-generated method stub
System.out.println(”Search finished”);
}
public void serviceSearchCompleted(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void servicesDiscovered(int arg0, ServiceRecord[] arg1) {
// TODO Auto-generated method stub
}
}
October 5th, 2007 at 16:39
hello sir,
i m very much interested in java. i have planned to develop a java application which should connect to my bluetooth enabled mobile.. and i have to use the mobile camera as a webcam and tranfer the video signals to my java application and transfer the video through other client using RMI.. is it possible to do.. and wht r all requirements i need.. i think it is complicated job.. but i have a good knowledge in JMF.. so bluetooth connection is tough part. can u help me….
October 5th, 2007 at 22:44
Sebastian: There might be few problems with your code.
1. Make LocalDevice and DiscoveryAgent variables as class members so that they stay alive after the constructor method call.
2. Add dirty Thread.sleep(10000); to your main(..) method after you have created a new instance of Blue class. This way the application will wait for the inquiry to complete. Bluetooth stack is using other threads for the discovery so you should have some mechanism to wait for the completion.
With these changes your code seems to work as I got the following output:
October 5th, 2007 at 22:48
Kishore: I have also planned to make a Java based webcam app (desktop + mobile) that would use the mobile phone as webcam. I was thinking about implementing it with Nokia API so that I can access the phone’s camera and then send camera image to desktop computer using bluetooth connection. I haven’t coded anything yet so I can’t say how hard it will be :)
October 6th, 2007 at 16:31
hello sir,
i dont know anything about netBeans.. without knowing netBeans is it possible to complie and run this sample code.. but i tried compile in normal mode.. but my compiler could not find “javax.swing.GroupLayout”.. wht can i do..
October 6th, 2007 at 16:52
hello sir,
I have removed The GroupLayout and changed the code to BorderLayout .. now ur sample code is compiled succesfully and it discovered my bluetooth enabled mobile phone.. thnak u for example.. if u have any simple bluetooth program code.. pls send to my e-mail..
bkishorekanna@yahoo.co.in
it will be very usefull for me to handle a bluetooth device with my java app… thnaks a lot for ur contribution..
October 6th, 2007 at 17:52
Thank you Tommi, it works, now I find the devices near to me. If I now want to send a date, for example the letter “a”, I know that I need to establish a connection to the device. I also think that I know how to do this, but I don’t know how I get the ServiceURl I need to enter in ….Connector.open(URL);
I thought it has something to do with the available services, so I tried to search for services with my DiscoveryAgent, when it found the device, but I don’t know what I should enter as the first and second parameter in the ag.searchServices(int[], UUID[], d, this); -method.
October 10th, 2007 at 06:36
hello sir,
now i m doing a project of chat server using rmi. i want to implement video Conferencing in my project.. is it possible to implement JMF in RMI.. r i have to do it using RTP.. i m very confused. so pls help me out of this.
October 10th, 2007 at 23:51
Hi Tommi,
Dear finally i got solved many problems in my project, like sending a file to several mobile fones one by one.
Now i have to make logs, like once the send file request is sent to a mobile, its regardless that the mobile accepts or rejects the file, the thing is that second time when the device is discovered again the request should not be send to the mobile again.
So my question is that how to skip the device which is discovered once?
Did you got my point???
Best Regards,
Romail Neil
October 11th, 2007 at 03:53
Hi everyone,
after uninstalling my 3rd party driver and letting windows xp sp2 install bluetooth driver (microsoft bluetooth stack) for my dongle, finally i can make any client server application as i wish. the problem solved in that pc.
now i’m upgrading my other pc from xp or xp sp1 to xp sp2 but… when i connected my dongle, it won’t install microsoft bluetooth stact automatically. the problem is i also cannot install widcomm driver because it won’t find my dongle.
my first and successul pc is pure win xp sp2 from the start. the other unsuccessful are upgraded xp and xp sp1 to xp sp2.
did anyone experiencing this problem?
October 16th, 2007 at 03:42
hello Tommi Laukkanen,
Great blog on the bluetooth.so easy to understand. was thinking of doing a final year project with bluetooth. i have until next may. how hard would it be to get a phone to interface with a computer. the phone would send out special request to the computer to display different videos. i do java programming in my course. from reading your blog people seem to have bad trouble with bluetooth. is it to risky to take on a bluetooth project cause i know no one that knows anything about it. i would be on my own.
Aswell what dongle would you recommend.what would the best and easiest to use.i will be using windows xp.will choose what ever stack with the dongle.
thanks for any reply.
P.S. if i was to do a project i would also create a blog on how i code my application. there is not enough out there to help like tutorials.need to help the community.
October 17th, 2007 at 10:06
Hello Tommi
Am new to Bluetooth domain.Can u pl help to search the bluetooth devices around my PC.. i need complete source code to search BT devices can u pl tel wat r the software requirements i need to install..
Am using netBeans to compile the code, Thank u pl help
October 21st, 2007 at 23:13
Hi Tommi m waiting for your reply dear please help me ……….. please please….
Best Regards,
Romail Neil
October 24th, 2007 at 08:12
Hello,
i am trying to send message from my desktop to mobile using bluetooth dongle through java programming.but i analysed yet there is no code for my project. either many of them using serial com port to send message from pc to mobile.can u pl tel whether its possible for me to send message from pc to mobile using bluetooth dongle and java programming.if so pl guide me .
October 25th, 2007 at 01:20
Dear Romail Neil , can you send me a piece of code to send
objets to phone?
I wait your news
Thank you
Cristian
October 26th, 2007 at 15:09
Hi Tommi Laukkanen,
First of all, great article!
I can run the application, but at run time i get this error:
ERROR: Error in main: null
I saw that you got 2 main’s in the code. It kinda confuses me because i dont know which file i should make the main file to execute from.
So i was wondering if you could make a project out of it with jcreator which will create a .jcw file which i can execute from. Then i know everything should work.
That program is lite and easier to understand for me.
Otherwise you could tell me which file is the main then i’ll try it myself to make a project out of it.
Either way, i thank you very much!
Yustme
October 29th, 2007 at 00:10
Hi everyone,
Please please please Tommi help me… or anyone please tell me how to skip a discovered device which is discovered once.. i need to complete my project very soon please……..
Christian give me your email address ill mail you the code…
Best Regards,
Romail Neil
October 29th, 2007 at 00:23
Romail: Maybe you could keep a list of discovered device addresses in a hashtable. You could store the device address to hashtable and then when new device is discovered just check if it already exists in hashtable? Is this something that you are looking for?
October 30th, 2007 at 16:15
Hi, with your great explanation I was able to find bluetooth devices in the area next to my laptop. Now I want to send numbers as a command to a Pico-Plug device that has a connection to the serial interface of a microcontroller. On sun.com I found an explination that shows how to do this. But I have a little problem with the following explanation that is shown there:
// assuming the service UID has been retrieved
String serviceURL =
“btspp://localhost:”+serviceUID.toString());
Can you please tell me how exactly I can get the „serviceURL“ because later I know that I need this URL for the method “Connector.open(serviceURL);”
I would be very happy to get help because than I think I could finish my project. Thank you
October 31st, 2007 at 09:55
This is the clearest paragraph that I have read for using bluetooth device in PC!
Clear, and simple ^_^
October 31st, 2007 at 23:56
Hi Everyone…
Tommi i have did that with vector but didnt worked, because i don know how to stop discovering. if you can help me with some specific conditions it will be great.
Thorsten wht i have understand from your question, at service url u have put the bt address of the specific device.
Best Regards,
Romail Neil
November 5th, 2007 at 02:49
Hi there,
Please please please please please please please please help me……..
i have to send file to mobile fones without pairing…
i have used the following line in discovery method.
adrProto = servRecord[i].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT,false);
and one more line used while sending file.
adrProto = “btgoep://”+ adr + “:” + channelId + “;authenticate=false;encrypt=false”;
please please please reply me as soon as possible…
secondly i dont understand even though when i paired the devices still sometimes i get the following error….
java.io.IOException: Failed to connect
at com.intel.bluetooth.BluetoothStackWIDCOMM.connectionRfOpenClientConnection(Native Method)
at com.intel.bluetooth.BluetoothRFCommClientConnection.(BluetoothRFCommClientConnection.java:32)
at com.intel.bluetooth.MicroeditionConnector.openImpl(MicroeditionConnector.java:195)
at com.intel.bluetooth.MicroeditionConnector.open(MicroeditionConnector.java:109)
at javax.microedition.io.Connector.open(Connector.java:79)
at de.avetana.obexsolo.OBEXConnector.open(OBEXConnector.java:103)
at Discovery.BluetoothBrowser.sendfile(BluetoothBrowser.java:111)
at Discovery.BluetoothBrowser.searchbtadress(BluetoothBrowser.java:84)
at Discovery.BluetoothBrowser.deviceDiscovered(BluetoothBrowser.java:64)
at com.intel.bluetooth.BluetoothStackWIDCOMM.deviceDiscoveredCallback(BluetoothStackWIDCOMM.java:200)
at com.intel.bluetooth.BluetoothStackWIDCOMM.runDeviceInquiryImpl(Native Method)
at com.intel.bluetooth.BluetoothStackWIDCOMM.runDeviceInquiry(BluetoothStackWIDCOMM.java:171)
at com.intel.bluetooth.DeviceInquiryThread.run(DeviceInquiryThread.java:77)
please please please reply me as soon as possible.
Best Regards,
Romail Neil
November 5th, 2007 at 11:41
I try to edit javax.swing.GroupLayout to javax.swing.BorderLayout, but it is forbidan.
The error is like :
Compiling 1 source file to C:\work\sc\bluetoothpresence\BluetoothPresence\build\classes
C:\work\sc\bluetoothpresence\BluetoothPresence\src\com\substanceofcode\presence\PresenceJFrame.java:58: cannot find symbol
symbol : class GroupLayout
location: package javax.swing
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
C:\work\sc\bluetoothpresence\BluetoothPresence\src\com\substanceofcode\presence\PresenceJFrame.java:58: cannot find symbol
symbol : class GroupLayout
location: package javax.swing
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
C:\work\sc\bluetoothpresence\BluetoothPresence\src\com\substanceofcode\presence\PresenceJFrame.java:65: cannot find symbol
symbol : class GroupLayout
location: package javax.swing
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
C:\work\sc\bluetoothpresence\BluetoothPresence\src\com\substanceofcode\presence\PresenceJFrame.java:64: package javax.swing.GroupLayout does not exist
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
C:\work\sc\bluetoothpresence\BluetoothPresence\src\com\substanceofcode\presence\PresenceJFrame.java:61: package javax.swing.GroupLayout does not exist
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
C:\work\sc\bluetoothpresence\BluetoothPresence\src\com\substanceofcode\presence\PresenceJFrame.java:75: cannot find symbol
symbol : class GroupLayout
location: package javax.swing
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
C:\work\sc\bluetoothpresence\BluetoothPresence\src\com\substanceofcode\presence\PresenceJFrame.java:74: package javax.swing.LayoutStyle does not exist
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
C:\work\sc\bluetoothpresence\BluetoothPresence\src\com\substanceofcode\presence\PresenceJFrame.java:70: package javax.swing.GroupLayout does not exist
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
8 errors
BUILD FAILED (total time: 0 seconds)
Thanks for help
November 20th, 2007 at 09:27
Thanks for all, i read all of yours comments, i got solutions of my problems which i am facing in developing my final year project.
November 20th, 2007 at 09:36
Another thing that i want to know is that, can bluecove also discovered bluetooth device which is running on same PC in sun’s emulator, i am asking this because when i download same code in mobile, then it works fine, but when i tyr to run it using sun’s wireless tool kit, it do not recognize bluetooth device.
November 20th, 2007 at 10:06
hi,
i really2 need ur help right now, where i need to send a message to mobile phone using bluetooth…
this is how’s it should works…
i need to scan all bluetooth devices within my range and automatically sending message to those phones. The process will keep on running until i press a stop button…
my big problem rite now is i dont know how to make the program keep on running (searching devices) and i dont know how to create stop button…
besides, i have a problem on displaying the list in Jlist (only one device display on the list)
please, please help me…. i’m running out of time….
p/s: can i get ur email tom so that i can email the coding for u…
November 26th, 2007 at 13:59
Zohaib, i m also doing a coleg project and not gaining any idea about the one as you mentioned above. So did you get your answer? Can u plz explain you project. My mail id is asgaralishah@gmail.com
November 30th, 2007 at 17:23
i tried the code on the same computer and it didnt work, i thought this was because both the client/server code was using the bluetooth at the same time, so i got another bluetooth dongle and loaded the server code on to my laptop, but when i select the server on the client, it says SPP service is not on there? I was also confused why the server didnt have setDiscoverable set, how else is the client meant to find the server? any replies really welcome :)
November 30th, 2007 at 19:06
oops wrong code, ignore :p
December 12th, 2007 at 08:46
Hi Tommi,
Thanks for your code.
I had already used S60 3RD EDITION SDK FOR SYMBIAN OS, FOR C++ with Carbide.c++ and I had worked with Chat eg for C++.
In the same way I want to develop a chat application between PC-PC using J2SE, Bluetooth and Emulator. With the help of your code I can detect the bluetooth devices.So I like to know which emulator should I use?
Do you have any idea??
Waiting for your reply.
Thanks & Regards,
Mary
December 13th, 2007 at 15:58
hi, It’s very nice blog.
I am developing a BT server (on PC) which need to connect few BT devices (cellularphones). I want to emulate/simulate it , I want to use the cellular emulators (the defualt of SUN) that will send BT msg to my BT server.
How can I do it?
December 19th, 2007 at 14:41
Fine….my dongle is not detected by the program. Can any1 help me with tht. M running out of time.
December 19th, 2007 at 23:30
Kayoni: That is quite wide question. You probably should ask that in Java forums instead of this blog entry.
Kushal: You could try out other Bluetooth drivers. I have noticed that Microsoft drivers work quite well for basic functionalities.
January 5th, 2008 at 14:39
dear Romail Neil ….
i saw your reply that appeared in the first.. can u help me in the project that u did for advertising in a shopping mall.. even iam trying out for the same…
i am at the scratch of the project.. do help me…
thank you
January 6th, 2008 at 07:45
hey pals….
my project is all about advetising in a shopping mall from the pc(server) to the bluetooth enabled mobiles… can u help me in anyways…
I need to submit in a month .. pls do help me..
thank you
January 23rd, 2008 at 22:30
Hello Tommi,
I am working with a similar project, I am having a problem to connect more than one Divice on my J2SE server. Can you help me on that?
Another doubt is about sending a msg or file from a PC to Device, without requiring a mobile jar software installed on device. Is it possible to do an application with J2SE to do than?? can you give me an example please??
Thank you so much.
February 3rd, 2008 at 00:13
What must i do??
February 4th, 2008 at 20:10
thanks sir for the so much of info i got where my mistake was.Anyway thanks a lot for providing such an information
February 4th, 2008 at 22:03
hi,
I m also trying to connect my pc to mobile using bluettooth in my desktop application.
But the problem is LocalDevice.getLocalDevice() returns me BluetoothStateException. I have uninstalled other bluetooth drivers and have only microsoft drivers installed. i have windowsxp sp2.
But the strange thing is when i try using the same code in j2me it runs fine. But in this case it is not able to find my Samsung SGH X700 java enabled mobile or any other mobile in the vicinity.
Can somebody help me out with this.
regards,
Monu
February 11th, 2008 at 21:48
Greetings fellow Java Jedi
I’ve recently purchased a Lego Mindstorms NXT kit: a very cool toy which can be controlled via Bluetooth. I’ve managed to write a simple NXT remote control using the Java Wireless Toolkit, and the experience got me interested in Java programming.
The Java “write once run anywhere” philosophy naturally led me to the ideal of writing a Bluetooth remote control for my Linux desktop, and I landed up here while googling for J2SE Bluetooth support. To make a long post short, I downloaded the Java code that’s referenced at the top of this page from http://www.javabluetooth.org. According to this tutorial you need the javax.comm package to compile the bluetooth library, but according to some googling on java serial comms programming Sun withdrew support for Win32 in their javacomm package. There is, on the other hand, a serial comms library that implements the API of Sun’s javacomm package called rxtx, which you can use as a replacement for the javacomm library. You can find it here. The rxtx library supports serial comms on multiple platforms. You only need to change the import javax.comm.* statements in your UARTTransport.java file with import gnu.io.* to make the http://www.bluetooth.org library compile.
I’ve managed to build and run your example program doing this, but haven’t had much luck during device discovery. I get the infamous “Unable to load HCIManager. org.javabluetooth.stack.hci.HCIException: BluetoothStack not initalized.” error message. I use a DLink DBT 120 USB Bluetooth dongle on my PC, so it’s either the comms hack that bytes me or the dongle is not set up correctly. Some googling is in order.
Anyway, thought that this could maybe help someone. Thanks for the handy tut.
May the source be with you…..
;-)
February 19th, 2008 at 17:55
hey tommi… real cool work man!! i had a few problems in the begining but just reading the queries was enough… i solved them and this code is working fine… plz include more help for any bt related program like image transfer or chat etc soon on this site… it’ll sure be appreciated by all…
February 21st, 2008 at 05:26
Hello Tommi,
I want to use the API javax.Bluetooth in J2SE to capture the Data coming throught my usb bluetooth from a Monitor.
plz can u help me ??
February 21st, 2008 at 06:30
Hi,
I started my implementation but I have a error :
javax.bluetooth.BluetoothStateException: Unable to load HCIManager. org.javabluetooth.stack.hci.HCIException: BluetoothStack not initalized.
at javax.bluetooth.LocalDevice.(LocalDevice.java:49)
at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:62)
at BluetoothBrowser.(BluetoothBrowser.java:30)
at BluetoothBrowser.main(BluetoothBrowser.java:43)
thank u;
February 27th, 2008 at 21:31
Tommi sir as our one of our project module is not working properly where we are getting wrong we dont know.We r trying to tranfer a file from PC to mobile so its not working properly.Can u suggest the some ref for that or some info abt it ie for a file transfer.
March 27th, 2008 at 00:15
Hello sir and everyone…! :)
gr8 article..helped me understand basic bluetooth programming. sir, plz do suggest some good tutorials or sites from wherein i can carry on my further project work in this area. i want to implement a bluetooth application which is mainly file transfer from pc to mobiles in vicinity.
everyone, plz do suggest.
thank you all
:)
March 30th, 2008 at 20:40
Hi,
I have been noticing alot of people have been having this problem with the HCI manager. I am having the same problem too (cannot load HCI manager error during runtime). I am also getting an error that says “Bluetooth stack not loaded”. This is happening with both my own code and the code for the project found on this website. Has anyone solved this problem? I have been looking everywhere and it looks like it could be a configuration problem..? Any help would be great.
March 30th, 2008 at 21:19
Dathan: What bluetooth drivers are you using on your computer? Did you install the BlueCove SDK? I suggest you to try out the normal Microsoft Windows drivers, I haven’t had much problems with those.
March 30th, 2008 at 21:46
Yeah it was a problem with the drivers. This website helped me fix the problem
http://bluecove.sourceforge.net/bluecove-examples/bluetooth-stack.html
Also, the bluecove jar file needs to be in the right folder. I put in under java\jdk1.6\jre\lib and everything worked fine. I also read that it needs to be in the ext folder under lib as well, so I put it in there for good measure. I tried both serial and USB bluetooth devices and the USB device was the one that worked, so there may be some issues with Windows recognizing and installing the Bluetooth drivers. Thanks for your help
April 8th, 2008 at 18:14
Hi, First thanks, for this website it is really great, i want to ask you about a error that i get when in i am trying to work with SDK s60,
javax.bluetooth.BluetoothStateException: SymbianOS error = -5 : General:\nFeature not supported (-5)
It seens that the feature is not supported, what should i do?
Thanks for any information
Cheers
April 10th, 2008 at 15:26
Alpi: Thanks. This entry have really been the most commented entry ever so I should probably write some more about the Bluetooth coding as it is quite hard subject to handle.
I’m not that familiar with the Symbian S60 SDK. It seems that your emulator (or device) doesn’t support Bluetooth or it is disabled.
April 10th, 2008 at 17:45
Thanks for this wonderfull support. i’m having a problem in running this application as m not much good in java.
The other thing is that i want to send video from my PC to mobile phones .
so i have to publish theses services and wait client.i don’t how we can do this.
Thanking You
Regards,
arial
April 14th, 2008 at 05:07
Hi!!!
When I started my application I had a problem:
javax.bluetooth.BluetoothStateException: Unable to load HCIManager. org.javabluetooth.stack.hci.HCIException: BluetoothStack not initalized.
I’m using Bluecove…
How can I solve this problem?
April 21st, 2008 at 17:14
My problem is that I want to receive an XML file via bluetooth in a running application.but the file is received in the SMS inbox and not in my application.Plzzzz help me.Its urgent……
April 21st, 2008 at 21:32
Guddu: How are you sending the file to the phone? Are you using OBEX for the file transfer? Did you check out this site (Using the JSR-82 API for OBEX Image Transfers) for some ideas?
April 22nd, 2008 at 09:39
Actually I m not sending. I,ve to write the code to receive file.sending is not in my hand.But ……ya file is sent by using OBEX.I’ve to get that file and display in my running application. is there any way to accept the XML file in a running application or to display that in my running application. I’ll parse it by myself.the problem is to receive.Plzzz help me dear……
May 1st, 2008 at 12:07
Hello, i search about bluecove and i saw ur project.
My OS is Fedora core 4, and when i use eclipse to compile my project use bluecove library, it said: Native bluecove not available. So what does it mean? Can u help me? Tomorrow i have to report about my program, but now… :(
May 1st, 2008 at 21:55
Le Quang: It seems that BlueCove doesn’t support Linux at the moment as it is marked as “TODO” platform. I’m not that familiar with the Bluetooth support on the Linux platform but maybe you could look into something like BlueZ?
May 11th, 2008 at 03:34
Hi Tommy,
i tried to install bluecove.jar in eclipse but i´m not sure that i did it right.
i added bluecive.jar as external JAR (project–>properties–>java build path–> libraries–>add external JAR´s) in eclipse.
i wrote an application and tried it on the mobile phone. it works on the mobile phone without any problems.
but on the notebook it cannot find other bluetooth devices.
i am working with eclipse, eclipseME, and sonyericsson sdk.
i hope you can help me.
thank you
May 20th, 2008 at 09:40
What a great find this page was!
Tommi - You are right. Finding a basic example about developing desktop applications with Bluetooth support is quite a pain. Thanks for putting together this article.
I immediately got cracking with it and everything was going smoothly until I saw that dreaded debug error many people are talking about:
javax.bluetooth.BluetoothStateException: Unable to load HCIManager. org.javabluetooth.stack.hci.HCIException: BluetoothStack not initalized.
After a whole day of banging my head, I decided to not use the JavaComm library I compiled from http://www.javabluetooth.org or the one Tommi generously provided here, rather I used the Java Communication API from Sun (comm2.0.3) and the demo could now detect Bluetooth devices!
Hopefully this might work for another hapless person pulling their hair out over the HCIException
June 1st, 2008 at 15:03
Hello everyone,
this seems to be the only place where i can get decent guidelines for doing bluetooth programming. i need to transfer an xml file from a pc to a mobile. some one please help with code for file transfer using obex. i understand the device discovery n all. need code for file transfer.. plsss help
anushree
July 14th, 2008 at 17:48
hi tommy,
i am wanting to develop an appl on a mobile phone that sort of streams data to a pc.However, i am not being able to connect to the pc.actually i the appl can discover the pc but it cannot discover any services.how do i go abt it.pls help.(i am using bluetooth dongle by ivt bluesoleil do i need anything else besides this?
thanks,
uday
August 27th, 2008 at 21:50
i am new to Netbeaans. Please tell me what type of project and herby package should I create in Netbeans so that the above bluetooth presence code works. It is very urgent. Please…….
September 2nd, 2008 at 21:02
You’ll need to create a normal Java application in NetBeans. The trick is to add BlueCove libraries to your project so that it identifies the javax.comm.* packages.
September 9th, 2008 at 10:05
Jay/Tommi : tks lot.great job. as u said , i remove the JavaComm library from (www.javabluetooth.org), i used the Java Communication API from Sun (comm2.0.3) and now the demo works fine….
one more problem…
now it shows
LOG: Start discovery
ERROR: Error in main: Bluetooth Device is not ready
LOG: Discovery end
but using IVT bluesoliel GUI, its working,but with the demo app,it shows the log like this….how to over come
tks in advance
elan78in@yahoo.com
September 12th, 2008 at 12:12
Hai tommi,
am i going in the right way?
i have to change
run:
BlueCove version 2.0.3 on widcomm
to
BlueCove version 2.0.3 on Bluesoleil
How to set the configuration…i cant understand the document given in
http://code.google.com/p/bluecove/wiki/Documentation
urs
elan78in@yahoo.com
September 20th, 2008 at 18:11
Thanks Lots! Great Job. This is enough to get me started. It’s quite hard to find tips for developing Bluetooth related applications for Windows.
Regards.
September 25th, 2008 at 14:28
Just today i have overcome this error…..
Steps:
1.Add a new file with ur Project named “bluecove.stack”
2.Place the content “Bluesoleil” in that file.
3.Now execute ur program.
Now it displays like
compile:
run:
BlueCove version 2.0.3 on bluesoleil
ITLAB-29
Here ITLAB-29 is my system Bluetooth Name
Thanks Tommi
By
elan elan8in@yahoo.com
September 25th, 2008 at 14:37
hi tommi,
may i get the sample code for PC Bluetooth chat….(Using L2Cap)
i have already done it for mobile to mobile…
Tks in advance
Urs
elan78in@yahoo.com
September 29th, 2008 at 10:00
hai
how to send the file via obex to mobile….using bluecove
elan78in@yahoo.com
October 14th, 2008 at 09:05
while am running the program who r all on the bluetooth devices there name and addresses are placed in the bluesloiel
suppose if any one switch off the bluetooth devices at that time they name and address also displaying .i do know how to write a code for automatic refresh for specific period.
October 22nd, 2008 at 19:44
Hi all,
I have some problem to compile a Bluetooth on my eclipse( Windows XP SP3)
I have this error:
osgi> 17:45:26.312 error BluetoothStack not detected
com.intel.bluetooth.BlueCoveImpl.(BlueCoveImpl.java:180)
Can’t initialize bluetooth: java.lang.RuntimeException: BluetoothStack not detected.
I use Bluecove, and i have the Blueooth Stack from my SP3 for windows xp.
Can someone tell me what i should do??
Thanks in advance
November 14th, 2008 at 12:16
HI
I want to push MIDP client to phone when they connect to PC via bluetooth.
Please help me or provide me some hint/ link which explains how it could be done.
Thanks