Android:SMSMessage类中用到的pdus这个变量是做什么用的?怎么解释它的含义?

如题所述

问题:Android:SMSMessage类中用到的pdus这个变量是做什么用的?怎么解释它的含义?
回答:
Android设备接收到的SMS是以pdu形式的(protocol description unit)。所以从intent提取数据时就会遇到pdus。
publicclassSMSReceiverextendsBroadcastReceiver {
@Override
publicvoidonReceive(Contextcontext, Intent intent) {
//---接收传入的消息---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null; String str = "SMS from ";
if (bundle != null) {
//---查询到达的消息---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = newSmsMessage[pdus.length];
for (inti=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
if (i==0) {
//---获取发送者手机号---
str += msgs[i].getOriginatingAddress(); str += ":";
}
//---获取消息内容---
str += msgs[i].getMessageBody().toString();
}
//---显示SMS消息---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
Log.d("SMSReceiver", str);
}
}
}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网