小编Ser*_*tan的帖子

Android通过名称或地址获取短信对话

我正在开发一个短信程序,我希望得到对话.
我编写了下面的代码,它工作正常,但我想知道它是否更有效

这是用于创建会话线程

       Uri SMS_INBOX = Uri.parse("content://sms/conversations/");
    Cursor c = getContentResolver().query(SMS_INBOX, null, null, null, "date desc");

        startManagingCursor(c);
        String[] count = new String[c.getCount()];
        String[] snippet = new String[c.getCount()];
        String[] thread_id = new String[c.getCount()];

        c.moveToFirst(); 
        for (int i = 0; i < c.getCount(); i++) {
            count[i] = c.getString(c.getColumnIndexOrThrow("msg_count"))
                    .toString();
            thread_id[i] = c.getString(c.getColumnIndexOrThrow("thread_id"))
                    .toString();
            snippet[i] = c.getString(c.getColumnIndexOrThrow("snippet"))
                    .toString();
            //Toast.makeText(getApplicationContext(), count[i] + " - " + thread_id[i]+" - "+snippet[i] , Toast.LENGTH_LONG).show();
            c.moveToNext();
        }
        c.close();
Run Code Online (Sandbox Code Playgroud)

根据会话线程获取地址

    for(int ad = 0; ad < thread_id.length ; ad++) …
Run Code Online (Sandbox Code Playgroud)

sms android

19
推荐指数
1
解决办法
8168
查看次数

标签 统计

android ×1

sms ×1