如果有办法以pdu格式获取收件箱短信,有人可以告诉我吗?
答案 0 :(得分:0)
我认为这会有所帮助
Object[] pdus = (Object[]) extras.get("pdus");
for (Object pdu : pdus) {
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdu);
}
答案 1 :(得分:0)
SmsMessage[] msgs = null;
Object[] pdus = (Object[]) mBundle.get("pdus");
if(pdus != null){
msgs = new SmsMessage[pdus.length];
Log.e(TAG, "pdus length : "+pdus.length);
for(int k=0; k<msgs.length; k++){
msgs[k] = SmsMessage.createFromPdu((byte[])pdus[k]);
Log.e(TAG, "getDisplayMessageBody : "+msgs[k].getDisplayMessageBody());
Log.e(TAG, "getDisplayOriginatingAddress : "+msgs[k].getDisplayOriginatingAddress());
Log.e(TAG, "getMessageBody : "+msgs[k].getMessageBody());
Log.e(TAG, "getOriginatingAddress : "+msgs[k].getOriginatingAddress());
Log.e(TAG, "getProtocolIdentifier : "+msgs[k].getProtocolIdentifier());
Log.e(TAG, "getStatus : "+msgs[k].getStatus());
Log.e(TAG, "getStatusOnIcc : "+msgs[k].getStatusOnIcc());
Log.e(TAG, "getStatusOnSim : "+msgs[k].getStatusOnSim());
String dateTime=getDate(msgs[k].getTimestampMillis());
messageTypeArray = messageTypeArray + "Inbox" + splitKey;
messageDateArray = messageDateArray + dateTime.substring(0, 11) + splitKey;
messageTimeArray = messageTimeArray + dateTime.substring(11, dateTime.length()) + splitKey;
messageNumberArray = messageNumberArray + msgs[k].getDisplayOriginatingAddress() + splitKey;
messageInformationArray = messageInformationArray + msgs[k].getDisplayMessageBody() + splitKey;
答案 2 :(得分:0)
IF you want all inbox message
Uri uriSMSURI = Uri.parse("content://sms");
Cursor cur = MainActivity.context.getContentResolver().query(uriSMSURI, null, null, null,null);
String sms = "";
String type = "";
while (cur.moveToNext())
{
int t = cur.getInt(9);
if(t == 1 )
{
type = "Inbox";
}
else if(t == 2)
{
type = "Send";
}
else if(t == 3)
{
type = "Draft";
}
Date callDayTime = new Date(Long.valueOf(cur.getLong(4)));
SimpleDateFormat timeFormat = new SimpleDateFormat("h:m a");
String time = timeFormat.format(callDayTime);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM:d");
String date = dateFormat.format(callDayTime);
messageTypeArray = messageTypeArray + type + splitKey;
messageDateArray = messageDateArray + date + splitKey;
messageTimeArray = messageTimeArray + time + splitKey;
messageNumberArray = messageNumberArray + cur.getString(2) + splitKey;
messageInformationArray = messageInformationArray + cur.getString(12) + splitKey;
sms += "From :" + cur.getString(2) + "\nMessage : " + cur.getString(12)+"\nType : " + type + "\nDate : " + date + "\nTime : " + time + "\n---------------\n";
// text.setText(sms);
}
cur.close();