6

此问题已多次报告,但仍未解决。我在三星的开发者网站StackOverflow中阅读了所有与该主题相关的消息/线程

让我用几句话再次描述整个问题:

  1. 开发人员过去常常通过简单的查询来获取 SMS 对话列表,例如:

    Uri.parse("content://mms-sms/conversations/"); Cursor cursor = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null);

    或类似的东西。这里的关键点是URI地址:content://mms-sms/conversations

  2. 每个人都知道这是非官方的,并且一个人这样做需要自己承担风险 -请参阅此处的证明链接

  3. 但是,关键点是一个简单的事实,此代码仅在三星 Galaxy S3 和某些型号的 Galaxy Tab 2 中无法正常工作。它NullPointerException使用堆栈跟踪生成:

    java.lang.NullPointerException at android.os.Parcel.readException(Parcel.java:1431) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140) at android.content.ContentProviderProxy.query(ContentProviderNative.java:366) at android.content.ContentResolver.query(ContentResolver.java:372) at android.content.ContentResolver.query(ContentResolver.java:315)

在世界其他地方/宇宙的所有其他设备中,它运行良好!奇怪吧?

我知道这样的答案:嘿,伙计,这是你的问题,因为不能保证上述 URI 的存在/正确性,但是,有人有更富有成效的想法吗?

我已经通过他们的论坛向三星的开发人员发布了问题。

4

3 回答 3

10

最后我想出了如何克服上述问题(我不确定它是错误,但无论如何它看起来像一个错误)。

可以通过此查询检索对话列表:

Uri.parse("content://mms-sms/conversations?simple=true"); 
Cursor cursor = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null);

这里的关键点是 URI content://mms-sms/conversations?simple=true

于 2012-11-30T07:37:10.633 回答
1

我也遇到了这个问题,atm好像没有解决办法。检查了@barmaley 的答案,它也为我产生了同样的异常

@edit my friend just checked this on his sgs3 and it works! but he cannot get body/adress column, but its a start! It is very very weird that it works on his not on mine. Mine sgs3 is from Polish distribution and his is from usa... if there is difference between regions this can be worse than expected

于 2012-11-30T07:50:30.150 回答
1

If only interested in SMS conversations, and want addition SMS columns you don't get with content://mms-sms/conversations?simple=true, then you can try doing your own grouping on the SMS in the ContentResolver query.

  • uri = content://sms
  • projection = "DISTINCT " + Inbox.THREAD_ID, Inbox.ADDRESS, Inbox.BODY, Inbox.DATE etc...
  • selection = Inbox.THREAD_ID + " IS NOT NULL) GROUP BY (" + Inbox.THREAD_ID
  • sortOrder = Inbox.DEFAULT_SORT_ORDER

Note that I had to insert a dummy condition 'IS NOT NULL' before GROUP BY, because of the way that ContentResolver adds brackets to the database query it generates.

于 2020-06-17T01:10:26.583 回答