ive been stuck on some problem when trying to handle incoming sms
message and to toast them. have no idea how to get over the problem.
please help.

this is my main java file - SmsApp.java

package com.android.project.smsapp;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import com.android.project.smsapp.R;
public class SmsApp extends Activity {
    /** Called when the activity is first created. */
        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent i = new Intent(this, Receiver.clss);
        startActivity(i);
    }
}

i also have a Receiver.java file

package com.android.project.smsapp;
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 Receiver extends BroadcastReceiver{
        @Override
        public void onReceive( Context context, Intent intent )
        {
                // Get the SMS map from Intent
        Bundle extras = intent.getExtras();
        String messages = "";
        if ( extras != null )
        {
        // Get received SMS array
        Object[] smsExtra = (Object[]) extras.get("pdus");
        // Get ContentResolver object for pushing encrypted SMS to the
incoming folder
//      ContentResolver contentResolver = context.getContentResolver();
        for ( int i = 0; i < smsExtra.length; ++i )
        {
        SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
        String body = sms.getMessageBody().toString();
        String address = sms.getOriginatingAddress();
        messages += "SMS from " + address + " :\n";
        messages += body + "\n";
        // Here you can add any your code to work with incoming SMS
        // I added encrypting of all received SMS
//      putSmsToDatabase( contentResolver, sms );
        }
        // Display SMS message
        Toast.makeText( context, messages, Toast.LENGTH_SHORT ).show();
        }
        // WARNING!!!
        // If you uncomment the next line then received SMS will not be put
to incoming.
        // Be careful!
        // this.abortBroadcast();
        }}

and the androidmanifst.xml is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
    package="com.android.project.smsapp"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".SmsApp"
            android:label="@string/app_name" >
                <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Receiver"
            android:permission="android.permission.RECEIVE_SMS">
                <receiver
                    android:name=".Receiver">
                <intent-filter>
                    <action
android:name="android.provider.Telephony.SMS_RECEIVED"/>
                </intent-filter>
            </receiver>
                </activity>
    </application>
</manifest>

the logcat is as follows

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to