+ Reply to Thread
Results 1 to 2 of 2

Thread: How to check for the incoming sms?

  1. #1
    Junior Member
    Join Date
    Aug 2012

    How to check for the incoming sms?

    I want to develop an app which will check for incoming sms.One more thing is that the app should run in the background.

  2. #2
    Junior Member
    Join Date
    Aug 2012
    we have to defined BroadcastReceivers as private internal members to an Activity. In this case, it is probably best to define the receiver separately and register it in AndroidManifest.xml using the <receiver>tag. This will allow your receiver to
    process the incoming events even when your application is not active

    public class SmsReceiver extends BroadcastReceiver { 
    private static final String SHORTCODE = "55443"; 
    public void onReceive(Context context, Intent intent) { 
    Bundle bundle = intent.getExtras(); 
    Object[] messages = (Object[])bundle.get("pdus"); 
    SmsMessage[] sms = new SmsMessage[messages.length]; 
    //Create messages for each incoming PDU 
    for(int n=0; n < messages.length; n++) { 
    sms[n] = SmsMessage.createFromPdu((byte[]) messages[n]); 
    for(SmsMessage msg : sms) { 
    //Verify if the message came from our known sender 
    if(TextUtils.equals(msg.getOriginatingAddress(), SHORTCODE)) { 
    "Received message from the mothership: "+msg.getMessageBody(), 
    <?xml version="1.0" encoding="utf-8"?> 
    <manifest …> 
    <application …> 
    <receiver android:name=".SmsReceiver"> 
    <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
    <uses-permission android:name="android.permission.RECEIVE_SMS" /> 

+ Reply to Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts