Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all messages by ThreadID in android

Tags:

android

sms

mms

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?

like image 476
Binary Wang Avatar asked Feb 22 '13 08:02

Binary Wang


2 Answers

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);
like image 136
vikki Avatar answered Sep 20 '22 03:09

vikki


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

like image 35
Karthick M Avatar answered Sep 21 '22 03:09

Karthick M