首页 > 代码库 > Android 拦截短信

Android 拦截短信

public class SMSMess extends BroadcastReceiver {@Overridepublic void onReceive(Context arg0, Intent arg1) {Bundle b=arg1.getExtras();if (b!=null){//从data对象里获取所有的短信,并把每一条短信转成Object对象Object[] pud_sms = (Object[])b.get("pdus");//准备一个SmsMessage的对象数组,对象数组长度与object数组同长SmsMessage[] sms = new SmsMessage[pud_sms.length];//将object数组里的每一条pdu格式的短信转换成SmsMessage格式的短信for (int i = 0; i < sms.length; i++) {sms[i] = SmsMessage.createFromPdu((byte[])pud_sms[i]);Log.e("----------one sms", "短信内容"+sms[i].getMessageBody()+":短信发信人:"+sms[i].getDisplayOriginatingAddress());}}}}

 

Android 拦截短信