使用内容提供程序查询获取特定号码的所有会话短信

时间:2013-03-15 10:48:21

标签: android sms android-contentprovider

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

通过获取intent对象并将该对象与记录地址查询(如此函数)进行比较来完成。“

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”但是它获得更多时间becoz我搜索所有短信地址到地址号码并且它需要很多时间...所以是任何解决方案,如果我在查询中检查该数字,这意味着此功能快速运行...

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

提前感谢..

0 个答案:

没有答案