Sms ContentObserver onChange() fires multiple times

后端 未结 4 1801
春和景丽
春和景丽 2020-12-09 13:36

I know this question has been asked multiple times, but nobody has been able to come up with a working answer from what I have seen.

Im working on an app to intercep

4条回答
  •  暖寄归人
    2020-12-09 14:03

    You can save last message's id and compare it to the id of the message that is returned by cur in onChange. you then can simply disregard the message if ids are the same.

    // might contain mistakes, but you'll get the idea:
    protected void querySMS() {
        Cursor cur = getContentResolver().query(u, null, null, null, null);
        cur.moveToNext(); 
        if (lastId == cur.getLong(cur.getColumnIndex("_id")))
            return;
        lastId = cur.getLong(cur.getColumnIndex("_id"));
        ... //continue as it was
    }
    

    However - GO SMS only prevents other app's from recieving Broadcast if the user selected this option (Recieve Settings - Disable other message notification) - so if the user does not want other apps to disturb him - I think it's good idea not to do so.

提交回复
热议问题