你可以试试这个,看看它是否适用于 Facebook Messenger 通知。即使这确实有效,我建议您等待更好的解决方案。
从 API 19 及更高版本开始,Notification
对象携带捆绑-首次创建时extras
传递的输入。因此,可以使用 form 的键从中提取 , 等信息。可以在此处找到密钥:链接。Notification.Builder
Notification
title
context
summary
Bundle
Notification.EXTRAS_XXXX
在重写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。不用说,这是一种解决方法,并且需要进行大量测试以确保它按要求工作。