0

受信トレイの SMS を pdu 形式で取得する方法があれば教えてもらえますか?

4

3 に答える 3

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;
于 2014-07-14T05:48:39.720 に答える
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();
于 2014-07-14T05:55:39.457 に答える
0

これが役立つと思います

     Object[] pdus = (Object[]) extras.get("pdus");
     for (Object pdu : pdus) {
     SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdu);
}
于 2013-05-22T11:19:25.180 に答える