最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

通知監(jiān)控NotificationListenerService onNotificationPosted重復回調問題

 更新時間:2023年02月01日 09:13:57   作者:自動化BUG制造器  
這篇文章主要為大家介紹了通知監(jiān)控NotificationListenerService onNotificationPosted重復回調問題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

正文

通過 NotificationListenerService 監(jiān)聽第三方應用的通知發(fā)現(xiàn),同一條通知,會回調兩次 onNotificationPosted 方法。

// 第一次回調
2023-01-31 11:42:31.082330  2483  2483 I NotificationMonitorService: onNotificationPosted:StatusBarNotification(pkg=com.tencent.wemeet.app user=UserHandle{0} id=11499522 tag=null key=0|com.tencent.wemeet.app|11499522|null|10076: Notification(channel=wemeet shortcut=null contentView=null vibrate=default sound=android.resource://com.tencent.wemeet.app/2131623938 tick defaults=0x6 flags=0x11 color=0x00000000 vis=PRIVATE)) - 1
2023-01-31 11:42:31.086442  2483  2483 I NotificationMonitorReceiver: notify time: 1675136670845, pending size: 1
// 第二次回調
2023-01-31 11:42:31.088771  2483  2483 I NotificationMonitorService: onNotificationPosted:StatusBarNotification(pkg=com.tencent.wemeet.app user=UserHandle{0} id=11499522 tag=null key=0|com.tencent.wemeet.app|11499522|null|10076: Notification(channel=wemeet shortcut=null contentView=null vibrate=default sound=android.resource://com.tencent.wemeet.app/2131623938 tick defaults=0x6 flags=0x11 color=0x00000000 vis=PRIVATE)) - 1
2023-01-31 11:42:31.090506  2483  2483 I NotificationMonitorReceiver: notify time: 1675136670845, pending size: 2

解決該問題的思路是如何判斷兩次回調的 StatusBarNotification 對象是同一個通知。

經(jīng)過日志分析,onNotificationPosted 的時間戳相差毫秒級別,且兩次 StatusBarNotification 對象的 postTime 是相同的。

通過記錄上一次 StatusBarNotification 對象,并與第二次的 StatusBarNotification 對象進行比較去重,

StatusBarNotification 對象有個屬性 key,可以作為唯一識別符:

    private String key() {
        String sbnKey = user.getIdentifier() + "|" + pkg + "|" + id + "|" + tag + "|" + uid;
        if (overrideGroupKey != null && getNotification().isGroupSummary()) {
            sbnKey = sbnKey + "|" + overrideGroupKey;
        }
        return sbnKey;
    }

并配合 postTime 屬性進行去重:

// 過濾同一條通知
if (lastSbn?.key == sbn.key && lastSbn?.postTime == sbn.postTime) {
		return
}

當然,如果你知道一些 Intent 中的額外信息,也可以作為過濾條件:

val text = extras.getString(Notification.EXTRA_TEXT)
val title = extras.getString(Notification.EXTRA_TITLE)
// other ...

以上就是通知監(jiān)控NotificationListenerService onNotificationPosted重復回調問題的詳細內容,更多關于NotificationListenerService onNotificationPosted的資料請關注腳本之家其它相關文章!

相關文章

最新評論

广平县| 荣成市| 金川县| 呈贡县| 隆德县| 蓬溪县| 夹江县| 鄂托克前旗| 河津市| 宕昌县| 富阳市| 鲁山县| 杭锦后旗| 安远县| 赣州市| 汶川县| 天台县| 兴山县| 阳谷县| 逊克县| 石景山区| 定日县| 肃北| 潼南县| 江油市| 西乡县| 辛集市| 贵定县| 沙田区| 五家渠市| 柳林县| 武夷山市| 屯门区| 甘洛县| 宣恩县| 忻州市| 南涧| 正定县| 建水县| 霍山县| 汉源县|