Install phoneME in Android to run JavaME middlets

As we all know, the Android is similar to JavaME because both runs on Java platform . However instead of executing the classfiles, Android add the extra step of converting the Java bytecode into alternative instruction set used by (into *.dex) Dalvik Virtual Machine, which makes it unable to run Java classfile (*.jar) normally used by JavaME.

Luckily, some brave soul has provided phoneME implementation for Android, which in turn enable users to execute Java MIDlet in Android. phoneME for Android can be downloaded from its website: http://davy.preuveneers.be/phoneme/?q=node/10#android

phoneme screenshot phoneme screenshot phoneme screenshot

What you need to do is to download phoneME Advanced – Foundation Profile + MIDP or phoneME Advanced – Foundation Profile + MIDP High Resolution (240×320). The midlet manager provided with the distribution requires OpenIntents File Manager, which is used to browse for midlet *.jad or *.jar file.

So far, almost all core MIDP 2.0 functionality is available from the phoneME *.apk. The only incompatibilities arises from midlets that use optional JSR, which usually causes midlet manager to crash.

a simple Click-A-Tell SendSMS HTTP POST API library

Click-a-tell is a simple web service that allows you to integrate sms sending capability into your web application. Its simplicity and wide range of API available is very attractive to small to medium web application developers. Among the API supported by Clickatell are :

  • HTTP POST
  • HTTP GET
  • FTP API
  • SOAP
  • EMAIL-to-SMS
  • COM Object

Clickatell website offers examples of how to use their API in several programming language including but not limited to : VB.net, PHP, ASP, ASP.NET,PERL, Python, Coldfusion, etc.

However I found that the example written for PHP is a little bit outdated and it uses the file() function to initiate HTTP GET request which is generally restricted on webservers as it pose a huge security risk. The other Clickatell class found through PHPClasses website are either too cumbersome for my project or supported other protocol than I intended to use.

As a result I wrote my own Clickatell SMS (clickatell_sendsms_0.5.zip) class specifically for my own use.

Here are a sample code using the SendSMS 0.5 class

<?php
require('SendSMS.php');

$sendsms = new SendSMS("username","password","HTTP POST API key");

/* if the login return 0, means that login failed, you cant send sms after this */
if  (  ($sendsms->login()) == 0  ) {
	die( "failed");
}

/*other wise, you can send sms using the simple send() call*/

$sendsms->send("0132073011","testing send sms - camna? boleh dpt ? - mr hafiz");

?>

You can download the clickatell_sendsms_0.5.zip”>SendSMS 0.5 PHP class from this website, note that the class is licensed under the terms of the GNU General Public License version 2, and the class is only meant to be use with Click-A-Tell HTTP POST API.

The class can also be use with the libcurlemu library whenever applicable.

JavaME JSR-179 Example Code : Detect Location via TinyGeocoder

I’ve completed the JSR-179 Location API code for reverse geocoding in JavaME. This code essentially is an expansion of the previous JSR-179 example that i’ve posted in the blog before, plus the Reverse-Geocoding feature, thanks to TinyGeocoder service.

J2ME GPS Reverse Geocoding mypapit

What this sample MIDlet does?
It obtain coordinates via the mobile phone JSR-179 Location API and subsequently display the name of the location using TinyGeocoder reverse geocoding service.

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
import javax.microedition.io.*;
import javax.microedition.location.*;
import java.io.*;

public class Geocoder extends MIDlet implements CommandListener
{
	public Display display;
	public Form form;
	private Command cmdExit,cmdOK;
	public StringItem si, sili;

	public Geocoder()
	{

		display =Display.getDisplay(this);
		form = new Form("Location Api test");
		cmdExit = new Command("Exit",Command.EXIT,5);
		cmdOK = new Command("OK",Command.OK,1);
		si = new StringItem("Coordinates", "Press OK");
		sili = new StringItem("Location", "");
		form.append(si);
		form.append(sili);
		form.addCommand(cmdOK);
		form.addCommand(cmdExit);
		form.setCommandListener(this);
	}

	public void startApp()
	{
		display.setCurrent(form);
	}

	public void pauseApp()
	{}

	public void destroyApp(boolean flag) {
		notifyDestroyed();
	}

	public void commandAction(Command c, Displayable d)
	{
		if (c == cmdOK){
			Retriever ret = new Retriever(this);
			ret.start();

		} else if (c == cmdExit) {
			destroyApp(false);
		}
	}

	public void displayString(String string)
	{
		si.setText(string);
	}

	public void showAlert(String message) {
		Alert alert = new Alert("Alert",message,null,AlertType.WARNING);
		display.setCurrent(alert,form);
	}

}

class Retriever extends Thread {

	private Geocoder midlet;
	Form formRunning;
	Gauge gauge;

	public Retriever(Geocoder midlet)
		{
			/**
			  * Constructor
			  *
			  * EFFECTS: Initialise the server and store midlet information
			  *
			  * @param midlet The main application midlet
			  * @param server Forecast Server URL
			  *
			  */
			this.midlet = midlet;
			formRunning = new Form("Retrieving Info");
			formRunning.append(new Gauge("Processing",false,Gauge.INDEFINITE,Gauge.CONTINUOUS_RUNNING));
			midlet.display.setCurrent(formRunning);

	}

	public void run()
		{
			/**
			* Entry point of the thread
			*
			* EFFECTS: call to connect() method
			*/
			try {
							checkLocation();
						} catch (Exception ex)
						{
							ex.printStackTrace();
							midlet.displayString(ex.toString());
			} finally {

			}

		}

	public void checkLocation() throws Exception
	{
		String string;
		Location l;
		LocationProvider lp;
		Coordinates c;
		// Set criteria for selecting a location provider:
		// accurate to 500 meters horizontally
		Criteria cr= new Criteria();
		cr.setHorizontalAccuracy(5000);
		cr.setVerticalAccuracy(5000);

		// Get an instance of the provider
		lp= LocationProvider.getInstance(cr);

		// Request the location, setting a one-minute timeout
		l = lp.getLocation(120);
		c = l.getQualifiedCoordinates();

		if(c != null ) {
		  // Use coordinate information
		  double lat = c.getLatitude();
		  double lon = c.getLongitude();
		  string = "\nLatitude : " + lat + "\nLongitude : " + lon;
		  new GetData(midlet,lat,lon).start();

		} else {
			string ="Location API failed";
		}

		formRunning.append("Obtained coordinates...");
		midlet.displayString(string);
	}
}

class GetData implements Runnable,CommandListener {

Geocoder midlet;
double lat, lon;

public GetData (Geocoder midlet, double lat, double lon) {

	this.lat = lat;
	this.lon = lon;
	this.midlet = midlet;

}

public void commandAction (Command cmd,Displayable disp)
{

}

public void start() {
       Thread t = new Thread(this);
       t.start();
}

public void run() {
	HttpConnection conn=null;
	InputStream is=null;
	String sb;

	try {
			String sUrl = "http://tinygeocoder.com/create-api.php?g="+""+lat+","+""+lon;
			conn = (HttpConnection) Connector.open(sUrl,Connector.READ);
			if (conn.getResponseCode() == HttpConnection.HTTP_OK) {
					is = conn.openInputStream();
					byte buf[] = new byte[128];
					int total =0;
					while (total < 128) {
						int count = is.read(buf,total,128-total);
						if (count<0) {
							break;
						}
						total += count;
					}

					sb = new String(buf,0,total);

				    if (sb.length() < 10) {
							midlet.showAlert("Connection error, please try again");
							is.close();
							conn.close();

							return;
					}

					  midlet.sili.setText(sb);
					//midlet.form.append(sb);
					//vectorized();
					//midlet.saveCurrency(false,midlet.vector);
					//midlet.display.setCurrent(midlet.form);
			} else if (conn.getResponseCode() == HttpConnection.HTTP_NOT_FOUND) {
					midlet.showAlert("URL not found");

			} else {
				midlet.showAlert("Server busy or unavailable. Please try again later");
			}

	} catch (SecurityException sex) {
		midlet.showAlert("Connection failed. You need to authorize this application to access network");
	} catch (IOException ioex) {
			midlet.showAlert("Connection failed. Please try again later.");
	} catch (Exception e){
		midlet.showAlert(e.toString());
		e.printStackTrace();
		//midlet.display.setCurrent(midlet.form);
	} finally {
		try {
			if (is != null) {
				is.close();
			}

			if (conn != null) {
				conn.close();
			}
		} catch (IOException ioexception) {}
			is =null;
			conn =null;
			midlet.display.setCurrent(midlet.form);

	}
}

public String URLEncode(String s)
{
		if (s!=null) {
			StringBuffer tmp = new StringBuffer();
			int i=0;
			try {
				while (true) {
					int b = (int)s.charAt(i++);
					if ((b>=0x30 && b<=0x39) || (b>=0x41 && b<=0x5A) || (b>=0x61 && b<=0x7A)) {
						tmp.append((char)b);
					}
					else {
						tmp.append("%");
						if (b <= 0xf) tmp.append("0");
						tmp.append(Integer.toHexString(b));
					}
				}
			}
			catch (Exception e) {}
			return tmp.toString();
		}
		return null;
}
}

The code requires mobile device which implements JSR-179 Location API and has been tested on Nokia E71 and 6210 Navigator.

Google Android Phone Kogan Agora delayed?

February 1st, 2009 No Comments   Posted in Android, Open Source

Probably a stale news for most of you, the touted second Google Android Phone on the market, Kogan Agora product has been canceled despite having received huge pre-orders. The official statement from Kogan Technologies website states that the Kogan Agora release is delayed indefinitely citing technical issues regarding is screen size and resolution.

Kogan Agora, estimated to be available by Christmas 2008, might not even be ready by this year (2009). Customer who pre-ordered Kogan is being refunded as this article were written.

Kogan Agora fakaped

Its a pity to see such affordable Google Android phone to be delayed indefinitely, while there are a lot of phone manufacturers behind Open Handset Alliance (OHA, the organization that backed Android), we have yet to see other Google Android phone surfaces besides HTC manufactured T-Mobile G1.

As for my personal opinion, I don’t think Android platform is worth investing in right now since the only supported Android phone in the market is the SIM-locked T-Mobile, and although there has been news that Motorola, Huawei and Sony Ericsson are preparing to release Android phone, I don’t think I will give in much hope for Android until I’ve seen on the shelf of my local mobile phone store (SIM-unlocked, just like normal phones that is)

Primosync: Synchronize Google Calendar with Mobile Phone

Primosync Google Calendar

This week, I’ve tried Primosync, a JavaME application which allows you to synchronize your Calendar, Events and activities with Google Calendar.

Primosync is compatible with mobile phone which supports JavaME JSR-75 PIM API, a feature that becoming common in latest modern phones.

Advantages of syncing phone calendar with Google Calendar :

  • You will be able to access your event, activities and reminders anywhere with internet connection
  • Your events and reminder will be more portable across various phone models as you can sync it with Google Calendar to update your Calendar
  • Easier to keep track of your reminder and events
  • As a backup measure in case if your mobile phone is stolen or lost

You can download it from Primosync Google Code project website (yes it is open source!) or from Primosync.mobi download site (mobile phone friendly). Available in 3 versions (Blackberry, JavaME Signed, JavaME Unsigned), for some reasons, I was unable to install the Signed version of Primosync in my E71. So I figure the Unsigned version might work in more phones.

So lets start syncing!

Create PC Bluetooth application easily with pybluez

October 23rd, 2007 1 Comment   Posted in Open Source, PDA, PocketPC, Tips, Tricks, Guide

pybluez is a python bindings for the bluez application which enables you to interface with bluetooth devices on your computer.

Combined with the power of python dynamic typing, you will be able to do Rapid Application Development and test mobile bluetooth application quickly on your computer

Here’s a snippets which combines pyosd and pybluez which scans for nearby bluetooth devices and display the result on screen :

import bluetooth
import pyosd
from time import sleep

p = pyosd.osd()

p.set_pos(pyosd.POS_MID)
p.set_align(pyosd.ALIGN_CENTER)
p.set_colour("green")

p.display( "Scanning for bluetooth device")

nearby_devices = bluetooth.discover_devices(duration=20, lookup_names = True)

str= "found %d devices" % len(nearby_devices)
print str
p.display(str)
sleep(2)

for name, addr in nearby_devices:
   p.display( "  %s - %s" % (addr, name))
   print (" %s - %s" % (addr,name))
   sleep(2)

Python enables Rapid Application Development on your computer without much fuss. Coupled with pygtk and wxPython acting as GUI, you can create a lot of bluetooth application to interface with your mobile devices, limited only by your imagination.

[tags]python,pybluez,bluetooth,gtk,gnome,linux,mobile,pda,programming,development,RAD[/tags]


iPhoneCanvas – Fancy List component class for J2ME

October 1st, 2007 1 Comment   Posted in J2ME / JavaME, Open Source

I found a really nice but simple to use fancy list chooser class that emulates an iPhone display. The class requires MIDP 2.0 supported phones and can replace the default and boring List chooser class into a stunning, smooth scrolling graphical menu (includes reflections) for your users to see

Here’s example screenshot of iPhoneCanvas demo in action :

These menu icons are generated from flat and boring thumbnails like these :

Download
iPhoneCanvas is licensed under the GNU General Public License and can be downloaded from listchooser Google Code project page

Demo
The iPhoneCanvas demo featured in above screenshot can be downloaded here – fancylist.jar, fancylist.zip (demo source code)

Please submit bug reports or suggestions at Google Code listchooser page

Foxrate – Open Source J2ME Currency Converter Mobile Application

September 28th, 2007 9 Comments   Posted in J2ME / JavaME, Mobile Software, Open Source, PDA
open source j2me currency converter

Foxrate mobile is a currency converter application for mobile devices. It is a relatively small application which supports converting from/to 35 different currencies used around the world.

Foxrate lifts you from the burden of updating currency rate by automatically retrieving latest currency information from remote server. The best part about foxrate is — it is available for free and open source!

Download Foxrate Mobile Currency Converter
Foxrate can downloaded from- Google Code’s Foxrate page and Getjar.com

Generic AboutForm class for J2ME / JavaME application

August 28th, 2007 No Comments   Posted in J2ME / JavaME, newbie, Open Source

I’ve seen a lot of J2ME / JavaME application authors create their own ‘About’ or ‘Help’ form to provide information regarding their MIDlet application. Most of this ‘About’ page are re-invented each time the author releases a new application generating inconsistencies between application.

Moreover there are also another breed of authors that take a far more lazy approach by abusing the ‘Alert’ class to include ‘About’ information. On most phones, This will severely limits the amount of text displayed on the phone screen regarding the application information.

The Solution : A generic AboutForm
In light of this situation, I decided to create a generic AboutForm (derives from the familiar ‘Form’ class) which provides a consistent look of a proper “About” page on your application. All you need to do is to initialize the class and use it just like ordinary “Form” class.

aboutformscreenshot.png

AboutForm class features

  • Consistent look on your applications
  • Reusability – You don’t need to rewrite the about form class
  • Pre-arrange layout, the application/company logo, name, copyright notice and hyperlink are nicely arranged on the form
  • Easy to use and inuitive
  • You can stop wasting your time creating an About form for each of your applications
  • Clean and straight forward – just initiate the class and let it do all the work for you

Here’s a snippets of example usage :

AboutForm aboutForm;
..
..
//initialize about form, place logo.png in res folder inside the MIDlet apps folder.
aboutForm = new AboutForm("About","AboutFormDemo 1.0","/logo.png");

//set copyright notice
aboutForm.setCopyright("mypapit","2007");

//set hyperlink
aboutForm.setHyperlink("http://mobilepit.com",this);

//set commandlistener
aboutForm.setCommandListener(this);

//add additional notice
aboutForm.append("This is a demonstration of generic AboutForm class.");

 ...
 ...

public void commandAction(Command c, Displayable d) {

       if (c == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        } else if (c == aboutCommand) {

		//display the about form
		display.setCurrent(aboutForm);

	} else if (c == aboutForm.DISMISS_COMMAND) {
//this will handle "Back"
//notice that aboutForm uses DISMISS_COMMAND as its Command object similar to Alert class in MIDP 2.0
			display.setCurrent(mainForm);
		}
}

Download AboutForm class (MIDP 2.0)
Here are the link to the downloads :

[tags]j2me,javame,midp,cldc,mobile,java,coding,programming,application,midlet,midlets[/tags]


JavaME Mobile Port Scanner Midlet

If you’re into port scanning and computer security then you might appreciate this little buster which enables you to scan remote host for open port. As with other network scanners, it assumes you have network access of some sort for its operation.

Mobile Port Scanner user interface enables you to input hostname (or ip address) of the remote host that you want to scan. Scanning is performed after pressing the “Scan” softkey button and giving permission for the midlet to access the network.

mobileportscanner2.png

What should be Improved
Although Mobile Port Scanner has done a great job at scanning remote host, I find that the midlet can be improved by providing an option for the user to select a list (or a range) of ports prior scanning.

The midlet should also include the usual service name for the port it scanned for increased usability.

Requirements

  • This application requires MIDP 2.0 / CLDC 1.0 compatible phone (most modern phone meet this requirements)
  • Phone which supports SocketConnection (Nokia S40 phones do not meet this requirement)
  • Telco that allows you to connect to outbound port other than port 80 and 8080

Other Information
Mobile Port Scanner is licensed under the terms of GNU General Public License 2.0 and you’re welcomed to download it via SVN from its project website.

A pre-compiled version of Mobile Port Scanner can be obtained below

Application Download

[tags]midlet,java,javame,j2me,security,nmap,mobile[/tags]


This blog is protected by dr Dave\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'s Spam Karma 2: 141487 Spams eaten and counting...