0

我正在创建一个显示所有收件箱短信的应用程序。在短信列表中,有一个按钮可以阅读该号码与我的所有对话。

它是通过获取意图对象并将该对象与像此函数这样的记录地址查询进行比较来完成的..`

public void readConversation() {
    try {

        StringBuilder smsBuilder = new StringBuilder();
        cur = getContentResolver().query(Uri.parse(SMS_URI_ALL), null,
                null, null, "date ASC");
        int smsEntriesCount = cur.getCount();

        Log.d("smsEntriesCount", "" + smsEntriesCount);

        if (cur.moveToFirst()) {
            do {

                data = new HashMap<String, String>();

                String smsAdress = cur.getString(
                        cur.getColumnIndexOrThrow("address")).toString();
                String smsbody = cur.getString(
                        cur.getColumnIndexOrThrow("body")).toString();
                String smsid = cur.getString(
                        cur.getColumnIndexOrThrow("_id")).toString();
                String smsdate = cur.getString(
                        cur.getColumnIndexOrThrow("date")).toString();
                String smstype = cur.getString(
                        cur.getColumnIndexOrThrow("type")).toString();
                String smsStatus = cur.getString(
                        cur.getColumnIndexOrThrow("status")).toString();
                String smsReadUnread = cur.getString(
                        cur.getColumnIndexOrThrow("read")).toString();

                String contactnamelist = getContactDisplayNameByNumber(smsAdress);

                if (smsAdress.equalsIgnoreCase(straddress.trim())) {
                    data.put("_id", smsid);
                    data.put("address", contactnamelist);
                    data.put("body", smsbody);
                    data.put("date", smsdate);
                    data.put("type", smstype);
                    data.put("status", smsStatus);
                    data.put("ReadUnread", smsReadUnread);
                    NumberList123.add(data);

                    Log.d("Conversation id", smsid);
                    Log.d("Conversation Address", smsAdress);
                    Log.d("Conversation body", smsbody);
                    Log.d("Conversation date", smsdate);
                    Log.d("Conversation type", smstype);
                    Log.d("Conversation status", smsStatus);
                    Log.d("Conversation Read(1)-Unread(0)", smsReadUnread);

                }
            } while (cur.moveToNext());

        }
        convolistnumber = new application();
        convolistnumber.setListConvo(NumberList123);

        Log.d(Tag, " Arraylist size " + NumberList123.size());
        Log.d(Tag, "Convo List" + convolistnumber.getConvoList().size());



        if (!cur.isClosed()) {
            cur.close();
            cur = null;

        } else {
            smsBuilder.append("no result!");
        } 

    } catch (SQLiteException ex) {
        ex.printStackTrace();
    }
}

`

通过使用此功能,我得到了该号码的所有对话,即“straddress”来自按钮单击的主要活动,但它得到了更多时间,因为我将所有短信地址搜索到 straddress 号码,这需要很多时间......所以如果有任何解决方案我在查询中检查了那个数字,这意味着这个函数运行得很快......

我也在尝试检查光标中的地址,但结果只发送了收件人的短信,我想要所有发送和收件箱短信,这意味着对话..

提前致谢..

4

0 回答 0