I have coded an application to receive sms in android 2.1 and show it in the form of a toast. But i'm not able to simulate the incoming sms. I tried doing it with emulator control in DDMS view. No luck.. After clicking send with incoming number and message nothing happens in the emulator.
I tried by starting two emulators and trying to simulate sending of sms but no luck here either..
please help me... here is my code :
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.wissen.sms"
- android:versionCode="1"
- android:versionName="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".MainAcivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <receiver android:name=".receiver.SMSReceiver" android:enabled="true">
- <intent-filter>
- <action android:name="android.provider.Telephony.SMS_RECEIVED" />
- </intent-filter>
- </receiver>
- </application>
- <uses-sdk android:minSdkVersion="7" />
- <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
- </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.telephony.SmsMessage;
- import android.widget.Toast;
- public class SMSReceiver extends BroadcastReceiver {
- private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
- /**
- * @see android.content.BroadcastReceiver#onReceive(android.content.Context,
- * android.content.Intent)
- */
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(SMS_RECEIVED)) {
- Bundle bundle = intent.getExtras();
- Object messages[] = (Object[]) bundle.get("pdus");
- SmsMessage smsMessage[] = new SmsMessage[messages.length];
- for (int n = 0; n < 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();
- }
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- import android.app.Activity;
- import android.os.Bundle;
- public class MainAcivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

