0

Creating a message app that backups the current messages within the inbox. The issue is that I cannot seem to add anything into my messages. I am trying to target a specific thread id.

The code below returns the following Uri, which I am not sure what it means as well: content://sms/inbox/0

public static final String SMS_URI = "content://sms/inbox";
public static final String ADDRESS = "address";
public static final String PERSON = "person";
public static final String DATE = "date";
public static final String READ = "read";
public static final String STATUS = "status";
public static final String TYPE = "type";
public static final String BODY = "body";
public static final String SEEN = "seen";
public static final String THREAD = "thread_id";


ContentValues values = new ContentValues();
values.put( ADDRESS, "+190000000" );
values.put( DATE, System.currentTimeMillis() );
values.put( READ, MESSAGE_IS_NOT_READ );
values.put( TYPE, MESSAGE_TYPE_INBOX );
values.put( SEEN, MESSAGE_IS_NOT_SEEN );
values.put(THREAD, "106");
values.put(BODY, "Adding SMS");
Uri uri = getContentResolver().insert( Uri.parse( SMS_URI ), values );
Log.v("MainActivity", "Done Adding SMS - Uri: " + uri.toString());

Any help or pointers would be appreciated. I should have all the appropriate permissions in my Android Manifest. Also looking at a SDK version between 19 - 23.

Ivan Zhang
  • 177
  • 1
  • 1
  • 7
  • 2
    Is your app the default SMS app? If not, it doesn't have write access to the Provider. – Mike M. Nov 23 '15 at 20:19
  • That was something I was thinking, since I wanted to both write and read from my inbox. Does this mean that I will first need to become the default SMS app, and this will give me access to write? – Ivan Zhang Nov 23 '15 at 22:25
  • 2
    Yep, pretty much. Keep in mind, however, that a default SMS app is responsible for many things, including writing all incoming messages to the Provider, issuing appropriate Notifications, handling both incoming and outgoing MMS, etc. It is not a trivial task to write a full SMS client. The only workaround I've figured out so far is for KitKat, as shown in [my answer here](http://stackoverflow.com/questions/27697282/android-kitkat-api-19-how-to-write-messages-in-sms-content-provider-without/27709655#27709655). I've not yet had a chance to tackle Lollipop or Marshmallow. – Mike M. Nov 23 '15 at 22:38
  • Do you have an example of how someone can make their app the default SMS? Or prompt it? I see other applications have the ability to prompt the user, but have not figure it out yet. Thanks! – Ivan Zhang Nov 24 '15 at 01:56
  • [My answer here](http://stackoverflow.com/questions/30127564/android-default-making-default-sms-app/30133663#30133663) shows the bare minimum requirements for your app to show in the system's default selection list. The [Tutorial](http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html) page linked in the question is a guide to the changes in the SMS API introduced in KitKat. The "Advice for SMS backup & restore apps" section gives examples pertinent to your situation. – Mike M. Nov 24 '15 at 02:53
  • you can also refer to this google link:https://android-developers.googleblog.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html – Rohit Gupta Jun 11 '17 at 09:22
  • Only one sms app that is your default app can write in inbox. Others can only read a copy of the inbox file. This thing is implemented from android kit kat and abhove. Try to make your app as a default app. The solution is given here- https://android-developers.googleblog.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html Use all the manifest data in your app as given here. – Sarthak Singhal Jul 05 '18 at 13:00

0 Answers0