content:// sms / address列并不总是返回“sender”的号码

时间:2012-02-18 16:47:22

标签: android sms

当我查询“content:// sms /”内容提供程序并从地址列中提取信息时;我总是得到消息是“来自”或“发送到”的电话号码。如果我收到消息,则地址是来自其他人电话的号码。当我发送消息时,地址就是我发送给的消息。

如果不查询相应的收件箱/已发送文件夹,“content:// sms /”文件夹中的邮件是已发送邮件还是已收到邮件,我该如何区分?

    Uri uri = Uri.parse("content://sms/");
    String[] columns = new String[] { "_id", "thread_id", "address", "person", "date", "body" };
    String selection = "thread_id = " + threadId;
    String sortOrder = "date DESC";
    String limit = "LIMIT " + String.valueOf(mItemsOnPage);

    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    String deviceNumber = tm.getLine1Number();

    Cursor cursor = getContentResolver().query(uri, columns, selection, null,
            sortOrder + " " + limit);

    if (cursor != null) {
        cursor.moveToLast();

        while (!cursor.isBeforeFirst()) {
            long messageId = cursor.getLong(0);
            String address = cursor.getString(2);
            long date = cursor.getLong(4);
            String body = cursor.getString(5);
            long person = cursor.getLong(3);
            cursor.moveToPrevious();
        }
    }
    cursor.close();

3 个答案:

答案 0 :(得分:4)

您需要在查询中包含列type。它包含一个 long ,表示您是在处理收到的(type == 1)还是已发送的(type == 2)消息。

这样你就会知道如何解释地址栏。

答案 1 :(得分:0)

public static final Uri SMS_Inbox = Uri.parse("content://sms/inbox");
public static final Uri SMS_Sent = Uri.parse("content://sms/sent");
public static final Uri SMS_draft = Uri.parse("content://sms/draft");
public static final Uri SMS_Queued = Uri.parse("content://sms/queued");
public static final Uri SMS_ALL = Uri.parse("content://sms/");

public static final int INBOX = 1;
public static final int SEND = 2;
public static final int DRAFT = 3;
public static final int QUEUED = 6;

答案 2 :(得分:-2)

类型5似乎是草稿消息类型(至少对于三星i9100)