1

How can I insert on SMS into inbox and set it as unread? I tried using the following code.

ContentValues values = new ContentValues();
values.put("address", "123456789");
values.put("body", "foo bar");
getContentResolver().insert(Uri.parse("content://sms/sent"), values);

Insertion is working. But I don't know how to set it as unread. Also please tell me what is the type of sms table columns 'status', 'read' and 'seen'? How can I use them? Thanks.

MithunRaj
  • 543
  • 2
  • 7
  • 19

2 Answers2

1

Use this values.put("status", SmsManager.STATUS_ON_ICC_UNREAD);. Status can be anything like read/unread/seen. I have keep it as unread.

Look at Message status

values.put("read", true);  // As Read

and

values.put("read", false); // As Un Read
Community
  • 1
  • 1
Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
  • 1
    Thanks for reply. I tried with this. But SmsManager.STATUS_ON_ICC_UNREAD is not available. SmsManager.STATUS_ON_SIM_UNREAD only is available. Anyway its not working. – MithunRaj Aug 01 '13 at 06:44
  • 1
    SmsManager.STATUS_ON_ICC_UNREAD is available with this package import android.telephony.SmsManager. Import this package – Tofeeq Ahmad Aug 01 '13 at 07:02
  • ok. I was using android.telephony.gsm.SmsManager. Now I changed. Still the status of message added to inbox is read.. – MithunRaj Aug 01 '13 at 08:01
1

You can set the Telephony.Sms.READ as 0/1 (Unread/Read)according to the requirement.

If messageDirection is

INCOMING then contentUri = Telephony.Sms.Inbox.CONTENT_URI

OUTGOING = Telephony.Sms.Sent.CONTENT_URI

    ContentValues smsValues = new ContentValues();
    smsValues.put(Telephony.Sms.ADDRESS, phoneNumber);
    smsValues.put(Telephony.Sms.BODY, smsMessage);
    smsValues.put(Telephony.Sms.DATE, System.currentTimeMillis());
    smsValues.put(Telephony.Sms.READ, 0);
    return context.getContentResolver().insert(contentUri, smsValues);
Sarthak Sharma
  • 246
  • 2
  • 11