android - 从通知中获取数据

标签 android notifications statusbar

我正在编写应用程序,但我不知道如何从 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/

相关文章:

android - 如何使用 PackageManager.addPreferredActivity()?

android - 在 subview 上使用 onclicklistener 获取 JSON 对象

android - 动画通知栏图标是否可以接受?

如果在所需的 Activity 中,Android 会阻止通知

android - 状态栏在工具栏上方是白色的

qt - 如何从 QMainWindow 中删除栏

Android 状态栏通知加载 sd 图标

android - 谷歌云消息 : 100 multiple senders limitation

使用 adb 命令捕获时,Android 4.4 不允许我保存图片

macos - 将通知中心与执行选择器一起使用