This manual shows how to set up a Java project on Eclipse running on Android smart devices which uses the MLPI to communicate with the target device.
To start programming in Java, you need a working Java environment. By default, this includes:
The Java downloads can be found and can be downloaded by courtesy of oracle: http://www.oracle.com/technetwork/java/javase/downloads/index.html. Eclipse can be downloaded at http://www.eclipse.org/downloads/. You can choose between 32-bit and 64-bit version. For this tutorial, "Eclipse for Java Developers - Juno(4.2)" has been used. But older versions of Eclipse(3.6) have also been successfully tested. For all downloads and informations regarding Android app development, it is recommended to have a look at http://developer.android.com/. There, you can find detailed instructions and articles how to program and develop for the Android platform.
Start by creating a new "Android Application Project" in your workspace:
In this example, Android 4.0 is targeted. But MLPI has successfully been tested to also work with older versions, like Android 2.3. Finish the wizard and create an app with a single activity.
To use the MLPI from Java, you need to add the javamlpi.jar library which can be found in the folder mlpi4Java/lib
of the MLPI-SDK. Add the MLPI to an existing project, by just dragging and dropping the javamlpi.jar from the lib
folder of the mlpi4Java
Toolbox to your project root libs
folder in the Package Explorer of your Eclipse workspace. It is recommended to add the library "as a link".
Next, add a folder armeabi
in the libs folder and drag and drop the file libmlpijavaandroid.so
from the folder mlpi4Java/bin/
... to it.
In a next step you should add the necessary permissions for your application to communicate via network to the manifest of your project. Therefore, open the file AndroidManifest.xml
and add the following lines in front of the <application> node.
Add a button and a text box to your layout. We want to connect to a device, when pressing the button and print the device name to the text box.
Insert the following MLPI code to the corresponding activity class (e.g. MainActivity.java
).
Click "Run" to start your application. Happy coding...