Sunday, February 22, 2009
I was in a need to show a date picker with a java application. After some searching I came into here for a free calendar component.
Might become useful for somebody.
And to show a time picker control, you can use the jspinner itself, nothing extra is required. It amazed me
JSpinner spinner = new JSpinner(sm);
JSpinner.DateEditor de = new JSpinner.DateEditor(spinner, "hh:mm");
spinner.setEditor(de);
You can do it in netbeans by going into the properties of jspinner and changing the Editor properties from there,
Labels: Calendar/Time, Java
Receive business card/vcard/contact from mobile device through java application in your windows/ubuntu pc
4 thoughts Written By Shimul at 8:22 AMWhen you have a bluetooth dongle you can receive business card/files/contacts from mobile devices using your bluetooth software. Now if you want to receive contacts/file in your own software and you also don't want to install any application in your mobile device then you can continue reading.
The main thing is to open a obex receiver in your bluetooth device from your application, then other remote device can do ServiceSearch and find your dongle to send contact/vcard/business card without installing any application.
The trick is done using OBEX, to know about OBEX google please.
I am going to use Java as my source language as there is already a API made named bluecove
I tried to find an already made project and couldn't find after some searching(may be my search strings were weak)
After one/two day i came to the bluecove code repository, there i found the source of it.
So i made a netbeans project of my own and is posted at the end of this post(i think if you are interested then you are now looking into the end section for the code ;) )
Ok no rush, the original source code of bluecove people are here. Thanks god i found it.
And my code in netbeans can be found here.
To run it in windows no problem, but to run in it newer ubuntu when this post was written you had to include bluecove-gpl with the project, which is already included and you will need to install libbluetooth-dev for ubuntu 8.10 with this command
sudo apt-get install libbluetooth-dev
I hope the code works.
Send files to mobile device using bluetooth from windows/ubuntu/linux
35 thoughts Written By Shimul at 6:14 AMSo basically the thing is, i want to send files to mobile devices without installing any software in mobile handset. So how can i do that? Obviously google.
You can send files to mobile device using OBEX, a file transfer protocol for bluetooth devices, it's in jsr82.
And there is a api known as bluecove which has things ready made :). Supported stack(don't ask me what it is, i know little about i) list can be found here. A list of jsr82 compatible handsets can be found here.
I work with netbeans, you can get the latest netbeans ide from here.
You will need the bluecove-api jar, and you can download from here. The jar i used was named "bluecove-2.1.0.jar", Now here is an issue, if you want your application to run in ubuntu/linux then you will also need a jar called "bluecove-gpl-2.1.0.jar" which can be found in here. So copy this jars to the netbeans project folder. And add these jar's in the project libraries, go to project properties and from libraries at left select add jar/folder and show the jars.
Now you are ready to use bluecove with your project. Do some coding things as you like.
Here I am going to make an application which will discover devices around it and send them a file.
I used real bluetooth devices and handset. There is also possible to use emulators to emulate bluetooth dongle and also mobile device. But I don't know how, you can let me know if you find a easy one.
Ok now coding time, the application has three main parts
1. UI which is shown to user
2. BluetoothBrowser: a class that discovers remote devices and put them in a list, and this class is also used to find the OBEX url for sending files to remote device.
3. A sender class which sends file to remotedevices using the OBEXUrl found previously.
Now, while starting to work first, i found some examples where connectionurl was hardcoded like
btgeop://address:9
But this was not working for me, this is a port number in remote device in which obex service is running, but this port number is not valid for all handsets. For nokia it works fine, but in Sony Ericsson the obex port number is 6, so to make the program independent a findObex function was used to query the remote device to know it's obex connection url and then it was used to send the file. So more generic way. This part almost made me to fail as I was not able to do while the port number was 9 with sony ericsson.
The other codes are there, you might find similarity with codes in the net. But what can i do , i am a google coder. So things are copy paste copy paste bla bla.
The application starts discovery first then tries to send a jpeg file from "C://a.jpg" file.
Enought talking, now the happy part, the Source Code :).
The full source can be found here. The code is not tested, i plugged my code from other projects and made a quick project. So if you find now working let me know.
By the way for linux things, you might have a look at here
For ubuntu 8.10 additional library is required, to install that library in terminal run this command
sudo apt-get install libbluetooth-dev
It will save your time, in ubuntu i was getting bluecove stack not found though my bluetooth device was there, just running the above command will solve the issue, And remember to include the bluecove-gpl-2.10.0 jar with your project. the gpl jar has to be with the same version of your main bluecove jar.
I think i am still not clear to you. what can i do i am bad at writing and explaining.
The next one i am wishing to write is "How you can receive contacts/vcard/business card" from mobile devices using obex.
First you have to install jdk by running this command in terminal
sudo apt-get install sun-java5-jdk sun-java5-plugin
for jdk 6
sudo apt-get install sun-java6-jdk sun-java6-plugin
Then download netbeans ide from here
The downloaded file will be a sh file, most probably in your desktop
Now open the terminal(from Application->Accessories)
Then go to your desktop folder or the folder in which you have downloaded the installer file
cd Desktop
Then run this command, the last portion of the command will be the name of the file you downloaded
sudo sh netbeans-6.5-ml-javase-linux.sh
That's it, your installer will start and the next processes are as usual.
More detailed instructions can be found in Netbeans Wiki page