【问题标题】:Reading SMS in android, showing wrong count在android中读取短信,显示错误计数
【发布时间】:2012-09-26 22:10:56
【问题描述】:

我正在尝试在 android 中读取短信。在我的清单文件中,我有:

<uses-permission android:name="android.permission.READ_SMS" />

我的代码:

Cursor cursor = getContentResolver().query(Uri.parse("content://mms-sms/inbox"), null, null, null,null);
((TextView) findViewById(R.id.info1)).setText("Number of messages: " + cursor.getColumnCount());

问题是我的收件箱中有超过 17 条短信,但它给出的输出是

消息数:17

我看过thisthisthisthis。谁能告诉我是什么问题?

【问题讨论】:

    标签: android sms


    【解决方案1】:

    您要求列数

    cursor.getColumnCount()
    

    这与您想要的非常不同:

    cursor.getCount()
    

    getCount() 返回光标中的行数,或者在这种情况下返回收件箱中的邮件数。

    getColumnCount()返回每行的列数;比如 id、sender、message、time 等。在这里阅读第二个答案:How many database columns associated with a SMS in android?

    【讨论】:

    • 哦,明白了,columnCount 告诉我属性,Count 告诉我条目。不是吗???三分钟后接受答复。 sof 这么说
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 2012-05-25
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多