【问题标题】:How to read the content intent from the notification如何从通知中读取内容意图
【发布时间】:2018-01-26 16:50:16
【问题描述】:

我正在使用NotificationListenerService 阅读状态栏上发布的通知。我能够阅读通知上的标题和文本,但找不到阅读设置到通知的操作和内容意​​图的方法。

https://developer.android.com/reference/android/service/notification/NotificationListenerService.html

【问题讨论】:

    标签: android android-intent android-notifications android-notification-bar android-statusbar


    【解决方案1】:

    在您的onNotificationPosted() 中,您可以访问StatusBarNotification。这样,您可以调用getNotification(),然后使用公共成员变量contentIntentactions 分别访问内容意图和操作。

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
      Notificiation notification = sbn.getNotification();
    
      PendingIntent contentIntent = notification.contentIntent;
      Actions[] actions = notification.actions;
    }
    

    【讨论】:

    • 谢谢。我如何从待处理的意图中获取意图。 getIntent 似乎是隐藏的,如果尝试使用反射获取方法,我会遇到异常。
    • @Libin - 这是故意不可能的。从 Intent 到 PendingIntent 的转换是一种方式,特别是使 Intent 不能被其他应用程序/系统修改。
    • 我已经看到应用程序阅读通知并再次发布。不知道他们是如何阅读的。当您点击这些通知时,他们能够启动意图。
    • 其中一个应用是未通知您可以撤消已关闭的通知。未通知应用程序将重新发布通知,并且还可以深层链接到点击时发布的实际应用程序。想知道如果我们无法阅读内容意图,这是如何工作的。
    • 不,PendingIntents 不可持久化。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 2021-04-11
    相关资源
    最近更新 更多