Before we dive into the source code, I thought it would be a good idea to explain where to get the tools needed for developing mobile applications. These are the tools:
- Java Development Kit
- Eclipse
- Sun Java Wireless Toolkit for CLDC
- EclipseME
- Bluecove (java bluetooth library)
- Java Runtime Environment for your mobile phone
- RXTX (serial port library)
The best part is, is that these tools are supposed to be working on Windows, Linux and Mac OS! (I haven't tested that, though!)
Java Development Kit (JDK)The application is coded in Java, and so are MIDlets. You can get a JDK from
Sun or
openJDK. Mac OS already has a JDK installed
by default. At the time of writing, I'm using openJDK 6 on Ubuntu.
EclipseYou should have heard about Eclipse before, if you haven't, try a quick Google search to find out more about it. In short: it's an open source
IDE, we'll be doing all of the coding with this program. Go to their
download page and download Eclipse IDE for Java EE Developers (~160 MB). Always download the latest version, but FYI I used Eclipse 3.4 a.k.a. Ganymede.
Sun Java Wireless Toolkit for CLDCWe are going to use this toolkit to run our MIDlets in an emulated device,
get it here.
Update: there is no official support for Mac OS, but
this guy seems to have got it working.
EclipseMEEclipseME is an Eclipse plugin to help develop J2ME MIDlets. On their site there is a very detailed
installation guide. In short:
Make sure you downloaded and installed Eclipse and the Sun Java Wireless Toolkit for CLDC first. Use the update manager in Eclipse to install EclipseME (it's all covered in the installation guide).
BluecoveBlueCove is a Java library for Bluetooth (JSR-82 implementation), without such a library we are unable to use Bluetooth in our applications. Here's the
download link. You need only one or two files depending on your operating system. Windows/Mac users only need bluecove-x.x.x.jar, Linux users also need the bluecove-gpl-x.x.x.jar file. (Latest stable version at time of writing: 2.1.0.)
Java Runtime Environment (JRE) for your mobile phoneA lot of devices come with a JRE nowadays, however, not all those devices support the Bluetooth specification, also known as JSR-82. That means that even if your device has Bluetooth, you would not be able to use it with your Java application. Check your device manual or see this (incomplete afaik)
list of devices which support JSR-82 natively, if your device has a JSR-82 implementation, you're in luck.
If your device does not have a JRE, you have to install one yourself if possible. If it's not possible, you will have to look for another device to test it on. Note that you do not need to have a JRE on your device to begin writing and testing the application, but I recommend you install it, without it, you won't be able to fully test your application (I'll disclose why in another post). phoneME is a very promising JRE for Windows Mobile. Precompiled binaries are
available here, make sure you download the phoneME Advanced Dual Stack version, the other versions are not capable of supporting Bluetooth and MIDlets. You need to copy a few files from Bluecove into the phoneME installation to enable the Bluetooth library on your Windows Mobile device, see
this description.
If you're interested in more information about phoneME, you can also visit the
official phoneME project website. As an alternative to phoneME, you can also
download Mysaifu JVM (currently version 0.4.1). This JRE cannot run MIDlets, though, but it can run Bluetooth enabled applications in combination with Bluecove. I do not have any experience with other mobile device operating systems, so if you do not have Windows Mobile and do not have a JSR-82 capable device, you'll have to do a little research of your own.
RXTX (serial port library)We are going to address the serial port directly with Java. (Yes, you can send data to the serial port from command line, but who'd use such a crude programming method? :) ) We need the RXTX library for this,
get it here. If you're on Ubuntu, you can install the package 'librxtx-java', the library will be available at /usr/share/java/RXTXcomm.jar.
When you downloaded and installed all the software, you're ready to start your first project (e.g. Bluetooth application). I will cover this another time.