Archive

Archive for December, 2008

Why Android? : Equality of applications

December 30th, 2008

In this series of articles we will be exploring why Android is considered to be future of mobile platforms.

One of the most important reason is All Android applications are equal. Android platform is developed as set of applications. You have a core engine which runs all these applications. The core engine is essentially a virtual machine which provides APIs to communicate with hardware resources to applications.

Apart from this core engine/virtual machine everything else in Android is an application.  So user can replace the default dialer software with some other customized one. You can change how your home window is displayed. You can replace absolutely any application installed on your phone.

From developer perspective, this opens up a whole new range of applications that you can build. It was not possible to this before Android. Most of the other mobile platforms come with set of applications which are hardwired into the system and can not be replaced. With Android, change is here. You do not have to live with boring applications any more.

Android

Android API – SMS handling

December 29th, 2008

Many new application will use SMS as data delivery platform. Reality shows, on-demand movies etc request users to send predefined formatted SMS. Similarly some applications are coming up which sends data to user using SMS. Let’s see how such an application can be built using Android platform.

Android API support developing applications that can send and receive SMS messages. The android emulator does not support sending of the SMS currently. But the emulator can receive SMS. Lets explore the android SMS support and develop a small program that listens to the SMSes received on the device (on emulator) and will show that message as notification.

The event handling on Android is done with the help of intents and intent receivers. The intents  announce (or broadcast) the event and intent receivers respond to the event. Intent receivers act as the event handlers.

Let’s define an intent receiver that can handle the SMS received event:

package com.wissen.sms.receiver;
/**
* The class is called when SMS is received.
*/
public class SMSReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// TODO
}
}

We need to configure this intent receiver to receive SMS receive event. For SMS receive event android has defined an intent as ‘ android.provider.Telephony.SMS_RECEIVED ‘. The receiver can be configured in AndroidManifest.xml as follows:

<receiver android:name=".receiver.SMSReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

To receive SMS, application also needs to specify permission for receiving SMS. The permission can be set in AndroidManifest.xml as follows:

<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

Now our intent receiver is all set to be called when the android device will receive SMS. Now we only need to retrieve the received SMS and show the SMS text in a notification.

Here is the code of intent receiver that will read the SMS from intent received and show the first message (pdu).

public void onReceive(Context context, Intent intent) {
		Bundle bundle = intent.getExtras();

		Object messages[] = (Object[]) bundle.get("pdus");
		SmsMessage smsMessage[] = new SmsMessage[messages.length];
		for (int n = 0; n &lt; messages.length; n++) {
		smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
		}

		// show first message
		Toast toast = Toast.makeText(context,
		"Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
		toast.show();
		}

The SMS received by the Android device is in the form of pdus (protocol description unit). Class SmsMessage, defined in android.telephony.gsm package, can store information about the SMS. The class can also be used to create SmsMessage object from received pdus. Toast widget is used to show the SMS body as an notification.

Running the Program:
Only remaining thing now is running the application and sending the SMS message to the emulator. An SMS message can be sent to the emulator in the DDMS eclipse perspective (Dalvik Debug Monitor Service). ‘Emulator Control’ window can be used to send SMS message (an incoming number has to be provided which can be anything).

Here is the application screen shot in action,

Android SMS receiver application

Android SMS receiver application

Download the sample code here

Join the forum discussion on this post - (1) Posts

Android API , ,

Hello Android

December 29th, 2008

Finally Google decides to enter mobile market. Big time.

Recently all the big companies have realized potential of the mobile market and users. Everyone who has funds available at disposal is looking at mobile market. We have big players now and with Google’s entry things are going to get really competitive. Users are going to be the people who win in all this competition.

This blog and this competency center for people who are -

  • Users of Android phones
  • Android application developers
  • Experts on mobile markets
  • Android evangelists and enthusiasts

We will be talking here about new developments in the world of Android and over all mobile markets. We will be providing in depth analysis of Android as commercial platform for mobile application delivery. We will provide hands on instructions, help, work arounds for Android application developers. Keep reading.

Android ,