Deleting Android Sms Programmatically

Deleting Android SMS programmatically

Actually, the code in my post is 100% correct. The problem was that Android needs some time to store the SMS upon receiving it. So the solution is to just add a handler and delay the delete request for 1 or 2 seconds.

This actually solved the whole issue.

EDIT (thanks to Maksim Dmitriev):

Please consider that you can't delete SMS messages on devices with Android 4.4.

Also, the system now allows only the default app to write message data to the provider, although other apps can read at any time.

http://developer.android.com/about/versions/kitkat.html

No exception will be thrown if you try; nothing will be deleted. I have just tested it on two emulators.

How to send SMS messages programmatically

How to delete SMS programatically in android

Pls check this answer https://stackoverflow.com/a/8851644/3020568

Your app should be configured as default SMS app for dealing with sms - above 4.4

Check this

http://android-developers.blogspot.in/2013/10/getting-your-sms-apps-ready-for-kitkat.html

Delete sms from another activity Android

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

public boolean deleteSms(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 {
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 && 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);
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));

ContentValues values = new ContentValues();
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=?",
new String[] { c.getString(4) });
Log.e("log>>>", "Delete success.........");
}
} while (c.moveToNext());
}
} catch (Exception e) {
Log.e("log>>>", e.toString());
}

How to delete all sms from inbox programmatically in android?

The delete uri is "content://sms/" + id;

Uri inboxUri = Uri.parse("content://sms/inbox");
int count = 0;
Cursor c = context.getContentResolver().query(inboxUri , null, null, null, null);
while (c.moveToNext()) {
try {
// Delete the SMS
String pid = c.getString(0); // Get id;
String uri = "content://sms/" + pid;
count = context.getContentResolver().delete(Uri.parse(uri),
null, null);
} catch (Exception e) {
}
}
return count;

How to delete particular inbox message in Android version 5.0 lollipop or in Kitkat?

After 4.4 you are not allowed to delete any sms messages from inbox unless your app is the "default sms app"

Beginning with Android 4.4, the system settings allow users to select a "default SMS app." Once selected, only the default SMS app is able to write to the SMS Provider and only the default SMS app receives the SMS_DELIVER_ACTION broadcast when the user receives an SMS or the WAP_PUSH_DELIVER_ACTION broadcast when the user receives an MMS. The default SMS app is responsible for writing details to the SMS Provider when it receives or sends a new message.

Other apps that are not selected as the default SMS app can only read
the SMS Provider
...

You can see More info here
just mentioned the important part below:

if your app is designed to behave as the default SMS app, then while your app is not selected as the default, it's important that you understand the limitations placed upon your app and disable features as appropriate. Although the system writes sent SMS messages to the SMS Provider while your app is not the default SMS app, it does not write sent MMS messages and your app is not able to write to the SMS Provider for other operations, such as to mark messages as draft, mark them as read, delete them, etc.

Programmatically delete SMS doesn't work

If you are trying this application after kitkat it won't work.

http://android-developers.blogspot.com.tr/2013/10/getting-your-sms-apps-ready-for-kitkat.html?m=1

See sms blockers in play store, they will inform you the same thing.



Related Topics



Leave a reply



Submit