2

I'm looking for a listener for when user deletes sms from the inbox.

any listener for delete sms in android My question is duplicate but the thread hasn't an answer.

Community
  • 1
  • 1

2 Answers2

4

Unfortunately, there is no broadcast intent for this. You can implement your own checker by loading SMS count and ids and compare this result with the previous one time-by-time. It looks not good and can drain battery if you will make this checking too frequently, but I think it's only one way to resolve problem.

Dimmerg
  • 2,113
  • 1
  • 13
  • 14
1

i see many sms manager apps doing that without any background process, if you delete one sms in one of them , the others immediately remove that sms too, i know that we can use ContentObserver but i don’t think this is the right way

in your activity :

   public static void InitializeObserver(Context c) {
    try {
        ContentResolver contentResolver = c.getContentResolver();
        Handler mSmsObserverHandler = new Handler(Looper.getMainLooper());
        SmsObserver mSmsObserver = new SmsObserver(mSmsObserverHandler, c);
        contentResolver.registerContentObserver(Uri.parse("content://sms/"), true, mSmsObserver);
    } catch (Exception e) {
    }
}

observer class :

public class SmsObserver extends ContentObserver {
SharedPreferences trackMeData;
private Context c;

public SmsObserver(Handler handler, final Context c) {
    super(handler);
    trackMeData = c.getSharedPreferences("LockedSIM", 0);
    this.c = c;
}

@Override
public void onChange(boolean selfChange) {
    super.onChange(selfChange);

}} 
Hamidreza Sadegh
  • 2,155
  • 31
  • 33