Your application will need to have the uses-permission for android.permission.RECEIVE_SMS in your manifest.
Once you have that you can register a broadcast receiver for android.provider.Telephony.SMS_RECEIVED
.
Then you'll want to create your receiver.
<receiver android:name=".SMSBroadcastReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Your receiver should extend the BroadcastReceiver and in the onReceive() method when you receive an intent for android.provider.Telephony.SMS_RECEIVED_ACTION
you want to retrieve the message and determine if it is one that you want to pay attention to.
Your code might look something like this.
public class SMSBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "SMSBroadcastReceiver";
private static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED"
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
if (messages.length > -1) {
//You have messages, do something with them here to determine if you want to look at them and other actions.
}
}
}
}
}