content://sms/ 地址列并不总是返回“发件人”数字

发布于 2025-01-07 06:09:22 字数 1143 浏览 1 评论 0原文

当我查询“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();

When I query the "content://sms/" content provider and pull information from the address column; I always get the phone number that the message is "from" or "sent to". If I receive a message, then address is the number from the other person's phone. When I send a message, then address is the message I am sending to.

How do I differentiate if a message in "content://sms/" folder is a sent message or received message without querying the respective inbox/sent folders?

    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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

稍尽春風 2025-01-14 06:09:22

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

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

You need to include the column type in your query. It contains a long indicating whether you are dealing with a received (type == 1) or sent (type == 2) message.

This way you'll know how to interpret the address column.

何时共饮酒 2025-01-14 06:09:22
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;
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;
一梦等七年七年为一梦 2025-01-14 06:09:22

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

type 5 seems to be a draft message type (for samsung i9100 at least)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文