Joke: How Smartphone users see each other (Android,Blackberry, iPhone)

August 26th, 2011 1 Comment   Posted in Android, iPad, iPhone, joke
joke

Source: Android and Me

T-Mobile Angry Birds Advertisement

August 15th, 2011 No Comments   Posted in Games, Youtube / Videos

Here’s a creative advertisement from T-Mobile, featuring Angry Birds!

How to use W3C Geolocation API in Mobile (Basic)

August 13th, 2011 No Comments   Posted in API, Location API, Web Service

Previously Geocoding from mobile web (or ‘ordinary’ web application) is achieved through Google Gears (as pre-installed in Android 1.5+). However the W3C Geolocation API Specification has render Google Gears obsolete as newer browsers has these functionality built-in (including mobile browser).

How to include Geolocation API in a Web Page?
The most basic code that you started is listed below, the code below tests if the browser have built-in support for geolocation. If it does have geolocation support, it will call either one of the callback “successCallback” or “errorCallback”.


if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
} else {
  error('Sorry, your browser does not support geolocation');
}

“successCallback” is call whenever the API call is successful. You need to create a function for “successCallback”, as shown in the example below:

function successCallback(pos) {
  var lat, long;

  lat = pos.coords.latitude ;
  long = pos.coords.longitude;

var element = '<p><a href="http://maps.google.com/maps?q='+lat+','+long+'&hl=en">Latitude: ' +lat+ ' Long: ' + long + '</a></p>';

alert(lat +','+long);
$('body').prepend(element);

The function will return the latitude and longitude data and stores it in ‘lat’ and ‘long’ variable, which is then displayed to the screen.

More »

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.

Don’t SMS and Drive, it’s bad for your health

September 3rd, 2009 3 Comments   Posted in General, SMS and MMS

Phone ReUnion: A little bit of iPhone Joke

March 9th, 2009 1 Comment   Posted in General, Smartphone

Porting JavaME apps to Android is easier with J2ME Polish

March 4th, 2009 2 Comments   Posted in Android, J2ME / JavaME, Mobile Software

Great news for JavaME developers! The J2ME Polish project has announced that their upcoming j2mepolish 2.1 toolkit suite will support porting JavaME apps to Google Android mobile platform automatically! This means that the current JavaME developers will enjoy the advantages of porting their existing mobile application to Android effortlessly.

Android Logo

According to their press release, the next j2mepolish release will focus on automating the process of converting JavaME MIDlets to iPhone application.

J2ME Polish 2.1: Android support?

Android Logo

Currently I’ve yet to see how a ported JavaME application would look like on an Android mobile phone, but hopefully it would be as good as the ordinary Google Android app. At this time of this writing, J2ME Polish 2.1 is only available as a preview release which can be downloaded from J2ME Polish website.

I’ll update this blog about this feature once J2ME Polish 2.1 has been released.

p/s: I’m Eager to know how a JavaME app will look like once its ported to Android.

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.

TinyGeo-coder : A cool free geocoding/reverse geocoding service

February 9th, 2009 4 Comments   Posted in Web Service

I was searching for a free and easy to use geocoding web service over the internet for my experiment involving Location Based Service (LBS). Then suddenly i came accross tinygeocoder, a web service which really suits my need.

tinygeocoder services that caught my eye :

  • geocoding – you can feed it with name of place like “San Francisco, CA” and it will return result in latitude and longitude pair “(37.775196,-122.419204)”
  • reverse geocoding – feed it with a coordinate, and the service will return you the name of the corresponding place.

Personally I like the “reverse geocoding” functionality more as it would be handy for my LBS project. Keep an eye for this blog as I’ll be posting JavaME JSR-179 (Location API) codes which utilizes tinygeocoder services.

p/s: If you find tinygeoder helpful, consider making donations to them.

Kirodict – a Compact, Lightweight JavaME mobile dictionary

Finally after spending a couple months working on this on and off personal project, I decided to release the final version of Kirodict – a lightweight mobile dictionary.

As it name implies, Kirodict was designed to be small in size while maintaining its functionality as a fully fledge dictionary for mobile and embedded device. Kirodict acts as a front-end to an RFC2229 (dict.org) compatible server which it obtain the word definition from.

Kirodict - compact mobile dictionary

Its small and compact size as well as its portability makes it an attractive application to be downloaded and installed on your mobile phone. Kirodict requires mobile phones with at least these feature :

  • MIDP 2.0 /CLDC 1.0 compatible phones
  • 128kB of free storage space
  • Phone with network connection (3G, GPRS, Wifi, wimax)

With lower requirements, it can be installed on a lower end phone without much problem. Kirodict does not use additional storage space as it does not cache its results.

Kirodict can be downloaded from Kirodict Google Code project website and it is licensed under the GNU General Public License version 2.0

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