0

I have a code to delete an SMS:

public void deleteSMS(Context context, String message, String number) {
    try {
        Uri uriSms = Uri.parse("content://sms/inbox");
        Cursor c = context.getContentResolver().query(uriSms,
                new String[]{"_id", "thread_id", "address",
                        "person", "date", "body" }, null, null, null);

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

                if (message.equals(body) && address.equals(number)) {
                    context.getContentResolver().delete(
                            Uri.parse("content://sms/" + id), null, null);
                }
            } while (c.moveToNext());
        }
    } catch (Exception e) {
        Log.e("deletesms", e.toString());
    }
}

And I have a code to call longclick:

@Override
public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {

    Toast.makeText(getBaseContext(), "Deleted SMS", Toast.LENGTH_SHORT).show();
    return true;
}

Q: how do I delete inbox SMS by long click? I second day looking answer on my question, but not found. I am disappointed.

P.S. I have android 4.2.2.

P.S.S. sorry for the question. I was exhausted.

Sergey Molyak
  • 310
  • 3
  • 14

0 Answers0