How to get all messages by ThreadID in android
Asked Answered
D

2

6

I tried to get all messages by thread id with uri:content://mms-sms/conversations/{threadId}, but it doesn't seem work and throws exceptions:

         java.lang.NullPointerException

         at android.os.Parcel.readException(Parcel.java:1333)

         at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:182)

         at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)

         at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)

         at android.content.ContentResolver.query(ContentResolver.java:311)

    ........

however, when I change it to content://sms/conversations/{threadId}, it will not throw these, but only works for sms, not for mms.

why?

Declared answered 22/2, 2013 at 8:28 Comment(1)
any guys have worked on such things?Declared
T
6

the sms and mms tables have different columns, the correct way is to fetch each on its own, that is

Cursor smsCur = cr.query(Uri.parse("content://sms/"), null,  "thread_id=" + threadId, null, null);
Cursor mmsCur = cr.query(Uri.parse("content://mms/"), null,  "thread_id=" + threadId, null, null);
Torbert answered 13/4, 2013 at 20:32 Comment(3)
yeah, maybe you are right about it. seems we have no other choice.Declared
From docs: @param selection A filter declaring which rows to return, formatted as an SQL WHERE clause (EXCLUDING the WHERE itself).Fluviomarine
cursor returns 0 in case of thisEpiphenomenon
T
1

The above code shows syntax error like that so i changed like this.

   Cursor c= getContentResolver().query(Uri.parse("content://sms/"), null,  "thread_id=" + messgid, null, null);

It works fine for me

Tuxedo answered 11/2, 2014 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.