Skip to content Skip to sidebar Skip to footer

Delete Sms From Another Activity Android

I access all sms using ('content://sms/inbox') in my custom list view currently i am getting address body and _id now i want to delete selected sms from another activity please gui

Solution 1:

Here is the quide to how to delete sms Deleting Android SMS programmatically For kitkat https://android-developers.googleblog.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html First you should choose your app as default sms app then you can delete or remove sms from there.. You can also refer to this post How to delete an SMS from the inbox in Android programmatically? here is the tutorial for deleting sms programmatically http://wisdomitsol.com/blog/android/sms/programmatically-delete-sms-in-android i hope you find these post helpful if any problem you can comment here.

1.First Add permission in manifest 2. write the method

publicbooleandeleteSms(String smsId) {
    boolean isSmsDeleted = false;
    try {
        mActivity.getContentResolver().delete(
                Uri.parse("content://sms/" + smsId), null, null);
        isSmsDeleted = true;

    } catch (Exception ex) {
        isSmsDeleted = false;
    }
    return isSmsDeleted;
}

you can now delete sms byIds

You can also try this code

try {
    UriuriSms= Uri.parse("content://sms/inbox");
    Cursorc= context.getContentResolver().query(
            uriSms,
            newString[] { "_id", "thread_id", "address", "person",
                    "date", "body" }, "read=0", null, null);

    if (c != null && c.moveToFirst()) {
        do {
            longid= c.getLong(0);
            longthreadId= c.getLong(1);
            Stringaddress= c.getString(2);
            Stringbody= c.getString(5);
            Stringdate= c.getString(3);
            Log.e("log>>>",
                    "0--->" + c.getString(0) + "1---->" + c.getString(1)
                            + "2---->" + c.getString(2) + "3--->"
                            + c.getString(3) + "4----->" + c.getString(4)
                            + "5---->" + c.getString(5));
            Log.e("log>>>", "date" + c.getString(0));

            ContentValuesvalues=newContentValues();
            values.put("read", true);
            getContentResolver().update(Uri.parse("content://sms/"),
                    values, "_id=" + id, null);

            if (message.equals(body) && address.equals(number)) {
                // mLogger.logInfo("Deleting SMS with id: " + threadId);
                context.getContentResolver().delete(
                        Uri.parse("content://sms/" + id), "date=?",
                        newString[] { c.getString(4) });
                Log.e("log>>>", "Delete success.........");
            }
        } while (c.moveToNext());
    }
} catch (Exception e) {
    Log.e("log>>>", e.toString());
}

Post a Comment for "Delete Sms From Another Activity Android"