我有一个广播接收器SMSApp,onReceive从intent读取bundleExtras.在这里,我如何从bundleExtras中读取电话号码?
if(intent.getAction().equals(SMS_RECEIVED)) { Bundle bundleExtras = intent.getExtras(); if (bundleExtras != null) { } }
解决方法
Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); final SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); }
现在,messages [0] .getoriginatingAddress()是地址,消息[0] .getMessageBody()是消息体.