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

问题描述 投票:1回答:1

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

    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是当前活动通知的数组。
android notifications android-notifications
1个回答
0
投票
  • 我正在努力寻找答案。希望这会有所帮助: 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(); }
© www.soinside.com 2019 - 2024. All rights reserved.