从 Android 通知中获取详细信息/扩展文本? [英] Getting Detail/Expanded Text from an Android Notification?

查看:16
本文介绍了从 Android 通知中获取详细信息/扩展文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个通知侦听器来查找 Gmail 通知.

I've implemented a notification listener to look out for a Gmail notification.

我想从通知中收集扩展文本 (bigtext),如下面的通知所示:

I want to collect the expanded text (bigtext) from the notification as shown in the notification below:

查看----转发的消息---"等,只有当用户展开通知以显示操作按钮时才会出现.

See "----Forwarded message---", etc. which only appears when the user expands the notification to show the action buttons.

这个字符串值没有出现在通知的EXTRAS"数据中...

This string value does not appear in the notification's "EXTRAS" data...

http://developer.android.com/reference/android/app/Notification.html

推荐答案

我在 Android 7 上运行 Gmail 时遇到了类似的问题.

I ran into a similar problem with Gmail running on Android 7.

最终,我意识到(在另一个线程的帮助下)他的解决方案与现有答案不同在这里 - 您可以通过不同的方式访问您正在寻找的内容:

Eventually, I've realized (with some help from another thread) that he solution was different from the existing answers here - what you're looking for can be accessed in a different way:

Bundle extras = statusBarNotification.getNotification().extras;extras.get(Notification.EXTRA_BIG_TEXT) == null ?null : extras.get(Notification.EXTRA_BIG_TEXT).toString();

这样,您将始终获得字符串或空值,即使您要查找的值最初不是字符串.这样做是因为直接调用 getString(Notification.EXTRA_BIG_TEXT) 会返回 null,至少在某些情况下是这样.

This way you will always get either a String or null, even if the value you're looking for isn't originally a string. This is done because calling getString(Notification.EXTRA_BIG_TEXT) directly would return null instead, at least in some cases.

如果还有任何其他值您不确定它们可能存储在哪里,您可以尝试遍历整个 extras 包,如此处所述.

If there are any other values you're not sure where they might be stored, you can try iterating through the entire extras bundle, as explained here.

这篇关于从 Android 通知中获取详细信息/扩展文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆