【问题标题】:Filtering application in NotificationListenerServiceNotificationListenerService 中的过滤应用程序
【发布时间】:2014-03-19 01:20:30
【问题描述】:

我正在使用NotificationListenerService 从通知中检索信息。实际上,我只能在文本视图中显示我在通知栏中看到的最后一个通知。如果可能,我希望过滤此方法并仅显示 whatsapp 通知。我可以获取包名称并将其显示在 LOG 中,但我不知道我是否进行了过滤。这是 NotificaionListenerService 的一部分

public void onNotificationPosted(StatusBarNotification sbn) {
        Notification mNotification=sbn.getNotification();
        if (mNotification!=null){
            Bundle extras = mNotification.extras;

            Intent intent = new Intent(MainActivity.INTENT_ACTION_NOTIFICATION);
            intent.putExtras(mNotification.extras);
            sendBroadcast(intent);

            TAG = "onNotificationPosted";
            Log.i(TAG,"Package Name" + sbn.getPackageName());

            Notification.Action[] mActions=mNotification.actions;
            if (mActions!=null){
                for (Notification.Action mAction:mActions){
                    int icon=mAction.icon;
                    CharSequence actionTitle=mAction.title;
                    PendingIntent pendingIntent=mAction.actionIntent;
                }
            }
        }
    }

我可以在其中看到创建通知的应用程序的包名称。我必须在那里制作过滤器吗?我该怎么做?谢谢

【问题讨论】:

    标签: java android android-notifications notificationservices


    【解决方案1】:

    就这么简单:

    if("com.the.package.name.you.want.to.filter".equals(sbn.getPackageName())) {
         //Do something
    }
    

    或者如果有多个,你可以把它们放在一个 hashmap 或 list 中,看看包是否 是否在里面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-14
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多