如何获取消息跟踪的短信正文?

How get the sms Body for a message tracking?

我想将消息放入字符串中并拆分消息。但是我无法将 "body" 表示的消息转换为字符串。如果您知道如何将消息正文放入字符串中,请告诉我。这是我的示例代码,

 protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fulldetail);

    lst=(ListView)findViewById(R.id.rldlist1);

    Uri in = Uri.parse("content://sms/inbox");
    ContentResolver cr = getContentResolver();
    Cursor c = cr.query(in, new String[]{"_id", "address", "body"}, "address = 'eZ Reload'", null, null);
    adapter = new SimpleCursorAdapter(this, R.layout.rowsms, c, new String[]
            {"address", "body"}, new int[]{R.id.lblreloadbody, R.id.lblreloadno});

    lst.setAdapter(adapter)

你可以使用String body = sms.getMessageBody().toString();看看这个代码:

        // Get the SMS map from Intent
        Bundle extras = intent.getExtras();
         
        String messages = "";
         
        if ( extras != null )
        {
            // Get received SMS array
            Object[] smsExtra = (Object[]) extras.get( SMS_EXTRA_NAME );
             
            // Get ContentResolver object for pushing encrypted SMS to the incoming folder
            ContentResolver contentResolver = context.getContentResolver();
             
            for ( int i = 0; i < smsExtra.length; ++i )
            {
                SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
                 
                String body = sms.getMessageBody().toString();
                String address = sms.getOriginatingAddress();
                 
                messages += "SMS from " + address + " :\n";                    
                messages += body + "\n";
                 
                // Here you can add any your code to work with incoming SMS
                // I added encrypting of all received SMS 
                 
                putSmsToDatabase( contentResolver, sms );
            }
             
            // Display SMS message
            Toast.makeText( context, messages, Toast.LENGTH_SHORT ).show();
        }
         

阅读更多信息:

http://www.apriorit.com/dev-blog/227-handle-sms-on-android

How to read the message content of a new in coming message in android?