gpt4 book ai didi

java - Android Notification Listener 重复 hell

转载 作者:太空宇宙 更新时间:2023-11-03 11:02:06 25 4
gpt4 key购买 nike

需要一点帮助 - 这让我费尽心思!

我是 ReadItToMe 的开发人员,这是一款可以读出您的消息并让您通过语音回复的应用程序。去年我一直面临和破解的问题是重复的通知。我将以 WhatsApp 为例。

如果我收到一个 WhatsApp 通知,快乐的日子,它就是一个通知。如果我从不同的聊天中收到另一个。我会收到一个群组通知,之前未读的聊天通知带有新的发布时间,因此您无法检查它是否来自过去,然后是新通知。

我尝试过的解决方案:

  • 通过在通知到达时使用它们的标题、消息和包名称创建通知的哈希码,然后在它们被取消时将它们从列表中删除 (onNotificationRemoved) 来保持读取的通知列表。但是你知道吗!在上面的场景中,所有通知都被删除然后重新发送,所以这个解决方案是无用的。

    • 比较时间戳,这不起作用,因为重复的通知有新的时间戳

    • 比较 key /id,这些在聊天中永远不会改变,因此它们不是单个消息通知所独有的

    • 还有很多我忘记了

    • 检查通知是否为群组以至少忽略它是行不通的,因为第一个通知始终是一个群组。只有当有多个通知时,“组”实际上是一个内容为“2 条新消息”的组。

有没有人知道或可以想出任何创造性的解决方案来准确地确定(80% 的准确率就可以)哪些通知是真正新的,哪些是以前发布的?或者这只是在 Android 上根本被破坏了......

最佳答案

我有同样的问题,我用这种方式解决了它,你可以使用“when”属性结合使用 when 的保存方式:

public void onNotificationPosted(StatusBarNotification sbn) {    
if (System.currentTimeMillis() - sbn.getNotification().when > 3000 ||
isInArray(sbn.getNotification().when)) {
//when != sbn.getPostTime()
//If notification is 3 seconds old, it is discarted
return;
} else {
//Else, push to the array of notifications "when-id" to compare next time
goNextPosition(sbn.getNotification().when);
}
... next part of code
}

long when A timestamp related to this notification, in milliseconds since the epoch. Default value: Now. Choose a timestamp that will be most relevant to the user. For most finite events, this corresponds to the time the event happened (or will happen, in the case of events that have yet to occur but about which the user is being informed). Indefinite events should be timestamped according to when the activity began.

https://developer.android.com/reference/android/app/Notification.html#when

如果有人遇到这个问题,请随时问我,对不起,我是西类牙人。

关于java - Android Notification Listener 重复 hell ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39871527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com