Getting Detail/Expanded Text from an Android Notification?

后端 未结 4 1143
北荒
北荒 2021-01-06 07:55

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

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

4条回答
  •  醉话见心
    2021-01-06 08:03

    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();

    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.

    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.

提交回复
热议问题