gpt4 book ai didi

android - 从通知中获取数据

转载 作者:行者123 更新时间:2023-11-30 02:49:49 25 4
gpt4 key购买 nike

我正在编写应用程序,但我不知道如何从 Notification 中获取数据。我有 NotificationListenerService(如 this),当出现新通知时,我收到 StatusBarNotification 对象。任何人都知道如何从这个对象中获取通知的标题和内容(教程中只有 tickerText)?

最佳答案

好的,我找到了简单的方法来做到这一点,但它在 android 19+ (KitKat 4.4.2) 上可用:

如果你想要通知的标题,你可以使用这样的东西:

String title = sbn.getNotification().extras.getString(Notification.EXTRA_TITLE);

extras 中有更多信息,如文本、进程、时间等 - 详细信息 here

sbn 对象是 StatusBarNotification 类对象(如何实现这个你可以在 this tutorial 中找到

如果您需要在早期版本的 Android 上执行此操作,您必须尝试来自 this topic 的任何答案.

关于android - 从通知中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24388295/

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