sarath sarath - 9 months ago 63
Android Question

Android sms reading by number

I am working on a sms application. in my App I have to list all the convrsation .SO i use the following Uri.


Its working fine.And the following is my code snippet.

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

for(int i=0;i<c.getCount();i++){
body[i]= c.getString(c.getColumnIndexOrThrow("body")).toString();

for (int i = 0; i < body.length; i++) {
System.out.println("body ="+body[i]);
System.out.println("number ="+number[i]);

The number prints each conversations number and body prints the each conversations last message. But i want to get each conversations whole message and also help me to conversation for a specific number.

Jul Jul
Answer Source

From Conversationscursor, You can get thread_id. Once you got thread_id, continue query from sms provider to return all message which has the same thread_id

Example : thread_id = 2

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

while (c.moveToNext()){

        Log.v("BODY", c.getString(11).toString()); // 11 is the index of body with project URI