广播

来源:互联网 发布:淘宝张氏痔光真的假的 编辑:程序博客网 时间:2024/06/02 11:27

public class IncomingSMSReceiver enxtends BroadcastReceiver{

public void onReceive (Context context,Intent intent){//自动调用

Object[] pduses = (Object[])intent.getExtras().get("pdus");//pdus获取短信

for(Object pdus :pduses){

byte[] pdusmessage = (byte[]) pdus;

SmsMessage.createFromPdu(pdusmessage);//转成可以读取的消息对象

String mobile = sms.getOriginatingAddress();//手机号

String content = sms.getMessageBody();//内容

Date date = new Date(sms.getTimestampMillis());

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");

}

}

}


manifest 中配置

<receiver android:name=".SMSBroadcastReceiver">

<action android:name="android.provider.Telephony.SMS_RECEIVED"/>

</receiver>

原创粉丝点击