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

通知監(jiān)控NotificationListenerService onNotificationPosted重復(fù)回調(diào)問(wèn)題

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

正文

通過(guò) NotificationListenerService 監(jiān)聽(tīng)第三方應(yīng)用的通知發(fā)現(xiàn),同一條通知,會(huì)回調(diào)兩次 onNotificationPosted 方法。

// 第一次回調(diào)
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
// 第二次回調(diào)
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

解決該問(wèn)題的思路是如何判斷兩次回調(diào)的 StatusBarNotification 對(duì)象是同一個(gè)通知。

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

通過(guò)記錄上一次 StatusBarNotification 對(duì)象,并與第二次的 StatusBarNotification 對(duì)象進(jìn)行比較去重,

StatusBarNotification 對(duì)象有個(gè)屬性 key,可以作為唯一識(shí)別符:

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

并配合 postTime 屬性進(jìn)行去重:

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

當(dāng)然,如果你知道一些 Intent 中的額外信息,也可以作為過(guò)濾條件:

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

以上就是通知監(jiān)控NotificationListenerService onNotificationPosted重復(fù)回調(diào)問(wèn)題的詳細(xì)內(nèi)容,更多關(guān)于NotificationListenerService onNotificationPosted的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

连州市| 紫金县| 彭阳县| 建湖县| 衡阳市| 会昌县| 永川市| 观塘区| 保定市| 武威市| 鄂托克前旗| 靖宇县| 龙陵县| 江源县| 玉环县| 当涂县| 垦利县| 永嘉县| 都匀市| 凤翔县| 肥乡县| 昌黎县| 阜平县| 揭东县| 晋中市| 北流市| 通化县| 吐鲁番市| 葫芦岛市| 山阳县| 三原县| 淮安市| 德阳市| 沈阳市| 波密县| 宣城市| 汉源县| 永川市| 竹北市| 郧西县| 大邑县|