title: Android KitKat (API 19) - How to write messages in SMS Content Provider, without sending them, from Non-Default App?
body: <p>I am trying to create an Android app that writes messages in the Sent Box of the system. These messages should not be sent over the GSM network to the recipient, the idea is only to write them in the Sent Content Provider.</p>
  
  <p>For now, I have this code:</p>
  
  <p><strong>Manifest File</strong></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_SMS"/&gt;
  </code></pre>
  
  <p><strong>Java Class</strong></p>
  
  <pre><code>private final String SENT_SMS_CONTENT_PROVIDER_URI_OLDER_API_19 = "content://sms/sent";
  
  ContentValues values = new ContentValues();
  values.put("address", mNumber);
  values.put("body", mMessage);
  
  if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT)
    mContext.getContentResolver().insert(Telephony.Sms.Sent.CONTENT_URI, values);
  else mContext.getContentResolver().insert(Uri.parse(SENT_SMS_CONTENT_PROVIDER_URI_OLDER_API_19), values);
  </code></pre>
  
  <p>For a device with an API version lower than 19, this implementation works just fine. For these older sdk versions, it is only necessary to access to the content provider defined by the uri <strong>content://sms/sent</strong>.</p>
  
  <p>For the newer sdk versions, this is not working. Apparently, Android changed its way of managing the SMS module in the KitKat release. According the next article, only the default SMS application can write and update the new SMS Content Provider (android.provider.Telephony.Sms.Sent - the previous content://sms/sent is also not available):</p>
  
  <ul>
  <li><a href="http://android-developers.blogspot.pt/2013/10/getting-your-sms-apps-ready-for-kitkat.html" rel="noreferrer">http://android-developers.blogspot.pt/2013/10/getting-your-sms-apps-ready-for-kitkat.html</a></li>
  </ul>
  
  <p>Considering the behavior of this app, it doesn't make sense to turn it the default SMS app. This app doesn´t need to read SMS messages from the content provider and should not send any message by SmsManager.getDefault().sendTextMessage. The only thing it should do is write some messages in the Sent Provider.</p>
  
  <p>As you can understand, it is also not acceptable and practicable to request the user to change the default app to mine and then go back to the previous SMS app, each time it is necessary to write a message in the Sent (this is suggested in the "Advice for SMS backup &amp; restore apps" section in the Android Developers Blogspot).</p>
  
  <p>The next article reveals some ways to unhide the option OP_WRITE_SMS:</p>
  
  <ul>
  <li><a href="http://www.androidpolice.com/2013/12/06/non-default-sms-apps-in-kitkat-can-still-write-to-the-sms-database-using-a-switch-in-app-ops-no-root-required/" rel="noreferrer">http://www.androidpolice.com/2013/12/06/non-default-sms-apps-in-kitkat-can-still-write-to-the-sms-database-using-a-switch-in-app-ops-no-root-required/</a></li>
  </ul>
  
  <p>Unfortunately, the next code stopped working for Android 4.4.2:</p>
  
  <pre><code>Intent intent = new Intent();
  intent.setClassName("com.android.settings", "com.android.settings.Settings");
  intent.setAction(Intent.ACTION_MAIN);
  intent.addCategory(Intent.CATEGORY_DEFAULT);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
  intent.putExtra(":android:show_fragment", "com.android.settings.applications.AppOpsSummary");
  startActivity(intent);
  </code></pre>
  
  <p>I am out of solutions to overcome this problem.</p>