通过content://sms/获取每个sms的电话号码

使用下面代码在用户和数字之间获取整个会话:

Uri SMS_INBOX = Uri.parse("content://sms/");
        String selection = "thread_id = " + thread_id;
        final String[] projection = new String[] { "*" };
        Cursor c = getContentResolver().query(SMS_INBOX, projection, selection,null, "date");
        startManagingCursor(c);
        String[] body = new String[c.getCount()];
        String[] address = new String[c.getCount()];
        if (c.moveToFirst()) {
            for (int j = 0; j < c.getColumnCount(); j++)
                Log.w("ColumnName", c.getColumnName(j));
            for (int i = 0; i < c.getCount(); i++) {
                body[i] = c.getString(c.getColumnIndexOrThrow("body")).toString();
                address[i] = c.getString(c.getColumnIndexOrThrow("address")).toString();
                Log.d("address-" + i, address[i]);
                Log.d("body-" + i, body[i]);
                String subject =  c.getString(c.getColumnIndexOrThrow("_id")).toString();
                Log.d("_id-" + i, subject);
                String thread =  c.getString(c.getColumnIndexOrThrow("thread_id")).toString();
                Log.d("thread_id-" + i, subject);
                Log.d("----", "----");
                c.moveToNext();
            }
        }

使用这段代码在一个会话中获得所有的信息,但是我不能找出哪个数字发送哪条信息。
如果获取 "address" 列,就一直返回相同的数字,所以不知道这条信息是用户发的,还是其它的号码。

列 总是只给出另一个数字。如果你想区分发送信息和接收信息,你应该使用'type'列。

body[i] = c.getString(c.getColumnIndexOrThrow("body")).toString();
if(c.getString(c.getColumnIndex("type")).equalsIgnoreCase("1")){
                // sms received
                msg_state[i]=1;
             }
             else {
                //sms sent
                msg_state[i]=0;
             }