我正在生成一个通知,如:
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
是当前有效通知的数组。答案 0 :(得分: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();
}