6

This issue was reported several times, but still not resolved yet. I read all messages/thread which somehow related to this topic either in Samsung's developers site or in StackOverflow

Let me again describe whole problem just in few words:

  1. Developers used to get list of SMS conversations through simple query like:

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

    or something like this. Key point here's URI address: content://mms-sms/conversations

  2. Everyone knows that it's unofficial and one's doing it on his own risk - see proof link here

  3. But, critical point here's a simple fact this code doesn't work properly only in Samsung Galaxy S3 and some models of Galaxy Tab 2. It produces NullPointerException with stacktrace:

    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)

In all other devices of the rest of the World/Universe it works well! Strange, huh?

I know answers like: hey dude, it's your problem, since presence/correctness of aforementioned URI doesn't guaranteed, nevertheless, does someone has more productive idea?

I have already posted question to Samsung's developers through their forum.

Community
  • 1
  • 1
Barmaley
  • 16,638
  • 18
  • 73
  • 146

3 Answers3

10

In the end I've figured how to overcome aforementioned issue (I am not sure that it's bug, but anyway it looks like a bug).

List of conversations can be retrieved through this query:

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

Keypoint here's URI content://mms-sms/conversations?simple=true.

Barmaley
  • 16,638
  • 18
  • 73
  • 146
  • Hey @barmaley, what if you want to get the thread_id from the `Uri` "content://mms-sms/conversations?simple=true". How would you do that? – Etienne Lawlor Jan 09 '13 at 06:55
  • Nevermind, i guess the '_id' column of "content://mms-sms/conversations?simple=true" is equivalent to the 'thread_id' column of "content://mms-sms/conversations" . – Etienne Lawlor Jan 09 '13 at 07:27
  • @barmaley Does your app still work on SG3 ? Im making a new app and Im having this problem – Thomas Feb 22 '14 at 19:11
  • 2
    There is no content type (ct_t) information the returned table. How do I determine is a message is SMS or MMS? – A.J. Feb 01 '18 at 00:52
  • @A.J. The KDE Connect developers [theorize](https://invent.kde.org/kde/kdeconnect-android/commit/418e1a813e8a3c60f4841e9a770ae4291ac66db8) that the `?simple=true` means MMS isn't supported, so the answer is always "it's SMS". – FeRD Aug 13 '19 at 22:36
  • 1
    @FeRD As the above-mentioned KDE Connect developer, I would like to be clear that I am just as confused as anybody. However, more experimentation today is suggesting to me that the data from the `?simple=true` is not very useful except insofar as you can take the _id column and go look for a matching thread_id in another content URI – Sompom Jun 07 '20 at 22:39
  • @Sompom Be that as it may, I'm fairly confident that you're safe in your characterization of the "probably asinine" reasoning (which feels awfully generous, assuming that any reason went into it) underlying all of this insane behavior. – FeRD Jun 09 '20 at 09:31
1

I also encountered this problem and it seems that there is no solving for it atm. Checked @barmaley answer and it also produce same exception for me

@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

Adam Fręśko
  • 1,064
  • 9
  • 14
  • `content://mms-sms/conversations?simple=true` produces different set of columns. E.g. address as snippet and so on, so you'd need to change your code – Barmaley Nov 30 '12 at 16:56
  • 1
    Yeah, was easy to fixt that thanks to `//prints columns names for (int i = 0; i < cur.getColumnCount(); i++) { Log.v("column names", cur.getColumnName(i).toString()); }` – Adam Fręśko Dec 03 '12 at 00:41
  • @AdamFręśko Did you manage to get it work finally ? Im having the same problem – Thomas Feb 22 '14 at 19:10
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.