我如何获得每个联系人的短信的数量成一个TextView?如何获得、联系人、数量、短信

2023-09-14 00:04:11 作者:与子偕臧

我有一个列表视图显示我的设备上的联系人。我正在试图做的是显示我的设备已经从每一个接触到一个TextView我的列表视图中收到的短信的数量。我只能够显示总数字从这code我的收件箱中的短信:

  //获取收件箱中的邮件总数
        字符串的文件夹=内容://短信/收件箱;
        乌里mSmsQueryUri = Uri.parse(文件夹);
        字符串列[] =新的String [] {人,地址,身体,日,状态};
        字符串排序顺序=日期ASC;
        。光标C = context.getContentResolver()查询(mSmsQueryUri,列,NULL,NULL,排序顺序);

        textview.setText(c.getCount());
 

与上述code的问题是,在我的列表视图中的每一行,这仅显示总。我怎么可以拆分到它的相应的触点之间的总数是多少?

最后的结果是这样的,如果我在我的收件箱中的 100条消息: 联系人:

富Manchuu:25

酒吧蜂:15

SNA FUU:10

李四:50

解决方案

 乌里SMS_INBOX = Uri.parse(内容://短信/通话/);

光标C = getContentResolver()查询(SMS_INBOX,NULL,NULL,NULL,NULL);

    startManagingCursor(C);
    的String []数=新的String [c.getCount()];
    的String []片段=新的String [c.getCount()];
    的String []的thread_id =新的String [c.getCount()];

    c.moveToFirst();
    的for(int i = 0; I< c.getCount();我++){
        算上[I] = c.getString(c.getColumnIndexOrThrow(msg_count))
                的ToString();
        THREAD_ID [I] = c.getString(c.getColumnIndexOrThrow(thread_id单))
                的ToString();
        段[I] = c.getString(c.getColumnIndexOrThrow(片段))
                的ToString();
        Log.v(算,算[I]);
        Log.v(线,THREAD_ID [I]);
        Log.v(片段,片段[I]);
        c.moveToNext();
    }
 

查看日志和问题就解决了​​。不要重新发布了同样的问题:How做我显示短信的数量从联系人接收到的?

手机总是收到莫名的贷款短信,小心了,教你如何屏蔽

I have a listview that displays the contacts on my device. What I'm trying to do is display the number of text messages my device has received from each contact into a textview within my listview. I have only been able to display the total number of text messages within my inbox from this code:

        // gets total count of messages in inbox
        String folder = "content://sms/inbox";
        Uri mSmsQueryUri = Uri.parse(folder);
        String columns[] = new String[] {"person", "address", "body", "date","status"}; 
        String sortOrder = "date ASC"; 
        Cursor c = context.getContentResolver().query(mSmsQueryUri, columns, null, null, sortOrder);

        textview.setText(c.getCount());

The problem with the above code is that for every row in my listview, this only shows the total. How can I split the total number between to it's corresponding contact?

The end result is like this if I had 100 messages in my inbox: Contacts:

Foo Manchuu: 25

Bar Bee: 15

Sna Fuu: 10

John Doe: 50

解决方案

Uri SMS_INBOX = Uri.parse("content://sms/conversations/");

Cursor c = getContentResolver().query(SMS_INBOX, null, null, null, null);

    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();
        Log.v("count", count[i]);
        Log.v("thread", thread_id[i]);
        Log.v("snippet", snippet[i]);
        c.moveToNext();
    }

See log and problem solved. Dont repost the same question : How do I display the count of text messages received from a contact?