import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.telephony.gsm.SmsManager;
import android.util.Log;
public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
if("android.provider.Telephony.SMS_RECEIVED".equals(action)){
Bundle bundle = intent.getExtras();
Object[] objs = (Object[])bundle.get("pdus");
for(Object obj : objs){
byte[] pdu = (byte[])obj;
SmsMessage msg = SmsMessage.createFromPdu(pdu);
System.out(msg.getDisplayMessageBody());
System.out(msg.getDisplayOriginatingAddress());
}
}
abortBroadcast();
}
}
androidmainfest.xml
<receiver android:name=".SmsReceiver">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>