0

How to delete incoming sms in android marshmallow?. i tried but as of my knowledge above kitkat we could not delete the inbox sms. if we need to delete inbox sms should make the app as default. my question is whatsapp deleting their sms once verification has done,how they doing the same and is possible to delete incoming sms without make my app as default?. sorry for my bad english.

    public void deleteSMS(Context context, long messageId) {
    try {
        Uri uriSms = Uri.parse("content://sms/inbox");
        Cursor c = context.getContentResolver().query(uriSms, new String[]{"_id"}, null, null, null);

        if (c != null && c.moveToFirst()) {
            do {
                long id = c.getLong(0);

                if (id == messageId) {
                    context.getContentResolver().delete(
                            Uri.parse("content://sms/" + id), null, null);
                    Log.e("Message:", "Message is Deleted successfully");
                }

            } while (c.moveToNext());
        }

        if (c != null) {
            c.close();
        }
    } catch (Exception e) {
        Log.e("Exception", e.toString());
    }

}
Floern
  • 33,559
  • 24
  • 104
  • 119
shakthivel
  • 199
  • 2
  • 3
  • 14

0 Answers0