如何获取短信机构的邮件跟踪?

时间:2015-04-03 06:59:26

标签: android string sms smsmanager

我想将消息输入字符串并拆分消息。但我无法通过“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)

1 个答案:

答案 0 :(得分:0)

您可以使用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?