Using broadcast receiver it's execute perfectly.
Asked
Active
Viewed 209 times
-2
-
Still not posted the complete code ..deleteSMS() is called where when ? .... and it is meant for deleting all the sms :) – Maveňツ Dec 01 '16 at 07:08
-
I've call delete sms method in on post execute method.. yes it's delete all the sms from inbox, actually i think i need to delete only read sms but i don't konw how can i do it..also i have update it – Namrata Dec 01 '16 at 07:21
-
Do it by storing the value of read sms body to sharedpreference and delete only those who are in sharedprefrence. – Maveňツ Dec 01 '16 at 10:52
-
@maven , can you please give example, I've save values in shared preference but i don't know how can i compare it. – Namrata Dec 01 '16 at 12:03
-
Is I'm correct? if(no.equals(Uri.parse(uri))) { count =getContentResolver().delete(Uri.parse(uri),null, null); } where in no my shared preference values are stored.. – Namrata Dec 01 '16 at 12:10
-
update your latest code in your question – Maveňツ Dec 01 '16 at 12:26
-
Possible duplicate of [Deleting Android SMS programatically](http://stackoverflow.com/questions/8614211/deleting-android-sms-programatically) – Maveňツ Dec 12 '16 at 04:57
1 Answers
-1
Add permissions in manifest file like
<uses-permission android:name="android.permission.RECEIVE_SMS"android:protectionLevel="signature" />
<uses-permission android:name="android.permission.READ_SMS" />
Then Add Intent Filter:
<receiver android:name="com.aquadeals.seller.services.SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
Get all SMS:
TelephonyProvider telephonyProvider = new TelephonyProvider(context);
List<Sms> smses = telephonyProvider.getSms(Filter.ALL).getList();
Deleting SMS:
Do it by storing the value of read sms body to sharedpreference and delete only those who are in sharedprefrence.
Uri inboxUri = Uri.parse("content://sms/inbox");
int count = 0;
Cursor c = 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;
// uri.
count =getContentResolver().delete(Uri.parse(uri),
null, null);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
All Android content providers like: Contacts, Call logs, Calendar, ... Full doc with all options

Maveňツ
- 1
- 12
- 50
- 89
-
I've already added all the permissions related to read sms , write sms , internate access and also access phone state.. – Namrata Dec 01 '16 at 06:35
-
@Zilu where is your brodcast receiver ? post complete code.. then I may help you – Maveňツ Dec 01 '16 at 06:48