如何检查当前活动通知的优先级?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何检查当前活动通知的优先级?相关的知识,希望对你有一定的参考价值。

我正在生成一个通知,如:

    NotificationCompat.Builder ncBuilder = new NotificationCompat.Builder(this);
    ncBuilder.setContentTitle("My Notification");
    ncBuilder.setContentText("You've a meeting today.");
    ncBuilder.setTicker("Please be there in the meeting.");
    ncBuilder.setSmallIcon(R.drawable.ic_launcher_foreground);
    ncBuilder.setAutoCancel(true);
    ncBuilder.setContentIntent(pendingNotIntent);
    ncBuilder.setPriority(NotificationCompat.PRIORITY_MAX);

    manager.notify("Notification Generator", (int)System.currentTimeMillis(), ncBuilder.build());  

在这里,我们可以看到我设置的优先级是PRIORITY_MAX。但在代码中,当我检查此通知的优先级时,它显示为PRIORITY_DEFAULT

我用来检查收到通知的优先级的代码是:

            if (currentNos[i].getNotification().extras.getInt(String.valueOf(NotificationCompat.PRIORITY_MAX)) == NotificationCompat.PRIORITY_MAX) {
                Toast.makeText(this, "This is a Max Priority Notification.", Toast.LENGTH_SHORT).show();
            } else if (currentNos[i].getNotification().extras.getInt(String.valueOf(NotificationCompat.PRIORITY_MIN)) == NotificationCompat.PRIORITY_MIN){
                Toast.makeText(this, "This is a Min Priority Notification.", Toast.LENGTH_SHORT).show();
            } else if (currentNos[i].getNotification().extras.getInt(String.valueOf(NotificationCompat.PRIORITY_LOW)) == NotificationCompat.PRIORITY_LOW){
                Toast.makeText(this, "This is a Low Priority Notification.", Toast.LENGTH_SHORT).show();
            } else if (currentNos[i].getNotification().extras.getInt(String.valueOf(NotificationCompat.PRIORITY_HIGH)) == NotificationCompat.PRIORITY_HIGH){
                Toast.makeText(this, "This is a High Priority Notification.", Toast.LENGTH_SHORT).show();
            } else if (currentNos[i].getNotification().extras.getInt(String.valueOf(NotificationCompat.PRIORITY_DEFAULT)) == NotificationCompat.PRIORITY_DEFAULT){
                Toast.makeText(this, "This is a Default Priority Notification.", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "Priority for this Notification is not set.", Toast.LENGTH_SHORT).show();
            }  

如何检查当前活动通知的优先级? 有人可以帮我弄这个吗?

  • 注意:currentNos是当前活动通知的数组。
答案
  • 我正在努力寻找答案。希望这会有所帮助: if (currentNos[i].getNotification().priority == NotificationCompat.PRIORITY_MAX) { Toast.makeText(this, "This is a Max Priority Notification.", Toast.LENGTH_SHORT).show(); }else if(currentNos[i].getNotification().priority == NotificationCompat.PRIORITY_HIGH) { Toast.makeText(this, "This is a High Priority Notification.", Toast.LENGTH_SHORT).show(); }else if(currentNos[i].getNotification().priority == NotificationCompat.PRIORITY_DEFAULT) { Toast.makeText(this, "This is a Default Priority Notification.", Toast.LENGTH_SHORT).show(); }else if(currentNos[i].getNotification().priority == NotificationCompat.PRIORITY_LOW) { Toast.makeText(this, "This is a Low Priority Notification.", Toast.LENGTH_SHORT).show(); }else if(currentNos[i].getNotification().priority == NotificationCompat.PRIORITY_MIN) { Toast.makeText(this, "This is a Min Priority Notification.", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(this, "Priority for this Notification is not set.", Toast.LENGTH_SHORT).show(); }

以上是关于如何检查当前活动通知的优先级?的主要内容,如果未能解决你的问题,请参考以下文章

当前一个片段中的某些任务完成时如何通知另一个片段中的适配器

如何从片段到活动而不会干扰片段的可重用性

如何在地图片段活动上显示按钮

刷新同一活动中剩余的当前片段(ListView 数据)

如何优化C ++代码的以下片段 - 卷中的零交叉

如何通过单击片段内的线性布局从片段类开始新活动?下面是我的代码,但这不起作用