Cannot delete SMS programatically (Default SMS app set)
<p>I try to <strong>delete all SMS from my phone</strong> with this func:</p>

<pre><code> public void wipeOutAllSMS(Context context) {
    try {

        int rowsDeleted = 0;

        Uri uriSms = Uri.parse("content://sms/inbox");
        Cursor c = context.getContentResolver().query(uriSms, new String[]{"_id", "thread_id", "address", "person", "date", "body"}, "read=0", null, null);

        if (c != null &amp;&amp; c.moveToFirst()) {
            do {
                long id = c.getLong(0);
                long threadId = c.getLong(1);
                String address = c.getString(2);
                String body = c.getString(5);
                String date = c.getString(3);

                // mLogger.logInfo("Deleting SMS with id: " + threadId);
                rowsDeleted += context.getContentResolver().delete(Uri.parse("content://sms/" + id), "date=?", new String[]{c.getString(4)});

                Log.i("Deleting_SMS", "Delete success for: " + address + ", message = " + body);

            } while (c.moveToNext());
        }

        Log.i("Deleting_SMS", "rows deleted: " + rowsDeleted);

    } catch (Exception e) {
        Log.e("Deleting_SMS", e.toString());
    }
}
</code></pre>

<p>Unfortunately, the <strong>"rows_deleted" always 0. It doesn't delete a single sms.</strong></p>

<p>I have added my manifest the followings:</p>

<p>Permissions:</p>

<pre><code>  &lt;uses-permission android:name="android.permission.SEND_SMS" /&gt;
    &lt;uses-permission android:name="android.permission.READ_SMS" /&gt;
    &lt;uses-permission android:name="android.permission.WRITE_SMS" /&gt;
</code></pre>

<p>Other things in order to be able to select my app as the default sms reader:</p>

<pre><code>&lt;!--The following things are needed for this app to became the default sms app in order to have the ability to delete an sms. --&gt;

        &lt;!-- BroadcastReceiver that listens for incoming SMS messages --&gt;
        &lt;receiver
            android:name=".android.broadcast.SmsReceiver"
            android:permission="android.permission.BROADCAST_SMS"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.provider.Telephony.SMS_DELIVER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/receiver&gt;


        &lt;!-- BroadcastReceiver that listens for incoming MMS messages --&gt;
        &lt;receiver
            android:name=".android.broadcast.MmsReceiver"
            android:permission="android.permission.BROADCAST_WAP_PUSH"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" /&gt;
                &lt;data android:mimeType="application/vnd.wap.mms-message" /&gt;
            &lt;/intent-filter&gt;
        &lt;/receiver&gt;

        &lt;!-- This one needs too--&gt;


        &lt;!-- Service that delivers messages from the phone "quick response" --&gt;
        &lt;service android:name=".android.broadcast.HeadlessSmsSendService"
            android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
            android:exported="true" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /&gt;
                &lt;category android:name="android.intent.category.DEFAULT" /&gt;
                &lt;data android:scheme="sms" /&gt;
                &lt;data android:scheme="smsto" /&gt;
                &lt;data android:scheme="mms" /&gt;
                &lt;data android:scheme="mmsto" /&gt;
            &lt;/intent-filter&gt;
        &lt;/service&gt;
</code></pre>

<p>I also ask for permissions on app start, which I eventually accept:</p>

<pre><code>if (!PermissionHelper.isPermissionGranted(this, Manifest.permission.SEND_SMS) || !PermissionHelper.isPermissionGranted(this, Manifest.permission.READ_SMS)) {
            PermissionHelper.requestPermission(this,
                    new String[]{
                    Manifest.permission.SEND_SMS,
                    Manifest.permission.READ_SMS
            });
}
</code></pre>

<p>(<strong>WRITE_SMS</strong> permission is not exists in <strong>Manifest.permisson</strong> so I cannot ask for that.)</p>

<p>I have also <strong>set the default sms reader on my device to my app.</strong> However I cannot delete a single sms.</p>

<p>Please help if you can.</p>

<p>I use android <strong>Marshmallow, no exceptions thrown.</strong></p>