内容://短信/地址栏并不总是返回"发件人的"数 [英] content://sms/ address column not always return "sender's" number

查看:155
本文介绍了内容://短信/地址栏并不总是返回"发件人的"数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我查询的内容://短信/内容提供商和拉从地址栏信息;我总是得到的消息是从或发送到的电话号码。如果我收到一个消息,那么地址从对方的手机数量。当我发送邮件,那么地址是我发送到消息。

我如何区分,如果在消息的内容://短信/文件夹发送消息或接收消息而不查询各自的收件箱/发送文件夹?

 开放的URI = Uri.parse(内容://短信/);
    的String [] =列新的String [] {_id,thread_id单,地址,人,日期,身体};
    字符串选择=的thread_id =+的threadId;
    字符串中将sortOrder =日期DESC;
    字符串限制=限制+将String.valueOf(mItemsOnPage);    TelephonyManager TM =(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
    串deviceNumber = tm.getLine1Number();    光标光标= getContentResolver()查询(URI,列,选择,空,
            中将sortOrder ++限制);    如果(指针!= NULL){
        cursor.moveToLast();        而(!cursor.isBeforeFirst()){
            长MESSAGEID = cursor.getLong(0);
            串地址= cursor.getString(2);
            长日期= cursor.getLong(4);
            串体= cursor.getString(5);
            长人= cursor.getLong(3);
            cursor.moveTo previous();
        }
    }
    cursor.close();


解决方案

您需要包括键入在查询中的列。它包含的的指示是否正在处理与接收到的(类型== 1 )或发送(类型== 2 )的消息。

这样,你就会知道如何跨preT地址栏中。

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

解决方案

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.

这篇关于内容://短信/地址栏并不总是返回"发件人的"数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆