简体   繁体   中英

listening incoming sms on android

the following program is my sample program for Listening incoming sms.It is created .apk file
with out error but it does not display the message please help me.the toast does not display any message if the emulator receive the message. My scenario is receive the sms ansd display the alert dialog box to user.that sms contanins email address depending on that address my app search the phone contacts and send the contact number of the emailId's person as reply message

public void onReceive(Context context,Intent intent)
{
    Bundle extras=intent.getExtras();
    String messages="";
    if(extras!=null)
    {
        Object[] smsExtra=(Object[]) extras.get("pdus");
        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";
        }
    Toast.makeText(context, messages, Toast.LENGTH_SHORT).show(); // not  display
    }
}//onReceive

my manifastfile

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="e.x.x"
  android:versionCode="1"
  android:versionName="0.1" >

<uses-sdk android:minSdkVersion="8" />

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



    <receiver android:name=".ex2" android:exported="true" > 
        <intent-filter android:priority="999" > 
<action    android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter> 
    </receiver>



</manifest>

I'm not sure about manifest. Try like in this example Android – Listen For Incoming SMS Messages I think android:priority="999" and android:exported="true" is a root of problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM