tags:

views:

186

answers:

1

hi there i want to start an application on receiving sms from a particular number. i am trying it with onMessageWaitingIndicatorChanged(boolean mwi){ } method but i m struggling. so, anyone there to help me in detail? Thanks

+4  A: 

You'll need to register a broadcast receiver for android.provider.Telephony.SMS_RECEIVED. The receiver can then check the number of the SMS and start your activity as appropriate.

So, you'll need to:

  • Add a uses-permission for android.permission.RECEIVE_SMS to your manifest
  • Declare a broadcast receiver in your <application/> element in the manfiest:

    <receiver android:name=".YourReceiverName"> 
        <intent-filter> 
            <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
        </intent-filter> 
    </receiver>
    
  • Create the receiver class, extending IntentReceiver.

  • In onReceiveIntent, you can get the relevant messages by calling Telephony.Sms.Intents.getMessagesFromIntent() and passing in the intent you're supplied.
  • If the number matches the one you want, you can then start an activity by calling startActivity
Chris Smith
Chris thanks 4 ur responseTher is a problem in Telephony.Sms.Intents.getMessagesFromIntent() Perhaps itz deprecated,so Wat to use instead ..
MAkS
You can use `SmsMessage.createFromPdu`. An array of PDUs is available from the Bundle which you can get from the intent - `byte[][] pdus = (byte[][]) intent.getExtras().get("pdus");` or so
Chris Smith