你可以试试这个,看看它是否与Facebook Messenger通知工作。即使这样做有效,我也会建议你等待更好的解决方案。
从API 19及以上版本开始,Notification
对象携带捆绑extras
- 当Notification
第一次创建时,输入传递给Notification.Builder
。因此,使用Notification.EXTRAS_XXXX
形式的密钥可以从此Bundle
中提取诸如title
,context
,summary
等的信息。钥匙可以在这里找到:Link。
在重写onAccessibilityEvent(AccessibilityEvent event)
方法:
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Parcelable data = event.getParcelableData();
if (data != null && data instanceof Notification) {
Log.i("", "We have a notification to parse");
Notification notification = (Notification) data;
// For API 19 and above, `Notifications` carry an `extras` bundle with them
// From this bundle, you can extract info such as:
// `EXTRA_TITLE` - as supplied to setContentTitle(CharSequence)
// `EXTRA_TEXT ` - as supplied to setContentText(CharSequence)
// `EXTRA_INFO_TEXT` - as supplied to setContentInfo(CharSequence)
// ... more at: http://developer.android.com/reference/android/app/Notification.html
Bundle b = noti.extras;
Log.i("Notification", "Title: " + b.get(Notification.EXTRA_TITLE));
Log.i("Notification", "Text: " + b.get(Notification.EXTRA_TEXT));
Log.i("Notification", "Info Text: " + b.get(Notification.EXTRA_INFO_TEXT));
/////////////////////////////////////////////////////////////////
// For API 18 and under:
// Pass `notification` to a method that parses a Notification object - See link below
List<String> notificationText = extractTextFromNotification(notification);
....
....
}
}
extractTextFromNotification(Notification)
可以是一个方法从这里:Link。毋庸置疑,这是一种解决方法,并且需要进行相当多的测试才能确保其按要求运行。
现在我们使用api19 +,所以它确实没关系。在未来,我们将支持旧手机,也许那时我会使用充气视图技巧,我有点喜欢! – sokie 2014-09-08 12:17:02
额外的领域证明工作完美!我现在正在使用它来处理其他通知消息。谢谢! – sokie 2014-09-10 08:35:54
@sokie'我现在正在使用它来处理其他通知消息。“太棒了!没想到建议你这样做。 – Vikram 2014-09-13 19:38:30