3

First of all, I am very much new to Android programming.

I have written a program to delete SMS. I have already tested this code in Jelly Bean and it was working fine. Even in simulator with Android Marshmallow is was working fine. Recently I updated my mobile to Marshmallow and now SMS are not getting deleted from the app. Even No error is throw. Below is the code. I search for solution and tried different ways, but still no solution.

public void delete(final String id, final String number, final long date) {
    Uri uri = Uri.parse("content://sms/inbox");
    ContentResolver cr = context.getContentResolver();
    Cursor c = cr.query(uri, null, "person is null and _id = ?", new String[] { "" + id }, null);
    if (c != null && c.moveToFirst()) {
        do {
            String pid = c.getString(c.getColumnIndex("_id"));
            String pnumber = c.getString(c.getColumnIndex("address"));

            Log.d("MyAPP", "id: " + pid);
            if (id.equals(pid) && number.equals(pnumber)) {
                Log.d("MyAPP", "Deleting SMS with id: " + id);
                try{
                    cr.delete(Uri.parse("content://sms/" + id), null, null);
                    Log.d("MyAPP", "Delete success.........");
                } catch (Exception ex) {
                    Log.d("MyAPP", "Error deleting msg");
                }
            }
        } while (c.moveToNext());
    }
}

Here is the log.

04-01 22:49:04.783: (1620): id: 39
04-01 22:49:04.783: (1620): Deleting SMS with id: 39
04-01 22:49:04.785: (1620): Delete success.........
Floern
  • 33,559
  • 24
  • 104
  • 119
Maulik
  • 63
  • 7

0 Answers0