1
0
mirror of https://github.com/danog/termux-api.git synced 2024-11-30 04:19:20 +01:00

fix notification api piority on Android version>=8

On Android v8 and later, changing priority needs NotificationChannel configuration.
This commit is contained in:
Akira 2020-03-10 10:42:08 +09:00 committed by Alessandro Caputo
parent 43dec9b13a
commit 6a8d97bd4c

View File

@ -62,8 +62,25 @@ public class NotificationAPI {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String priorityExtra = intent.getStringExtra("priority");
if (priorityExtra == null) priorityExtra = "default";
int importance;
switch (priorityExtra) {
case "high":
case "max":
importance = NotificationManager.IMPORTANCE_HIGH;
break;
case "low":
importance = NotificationManager.IMPORTANCE_LOW;
break;
case "min":
importance = NotificationManager.IMPORTANCE_MIN;
break;
default:
importance = NotificationManager.IMPORTANCE_DEFAULT;
}
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
CHANNEL_TITLE, NotificationManager.IMPORTANCE_DEFAULT);
CHANNEL_TITLE, importance);
manager.createNotificationChannel(channel);
notification.setChannelId(CHANNEL_ID);
}
@ -93,7 +110,6 @@ public class NotificationAPI {
break;
default:
priority = Notification.PRIORITY_DEFAULT;
break;
}
String title = intent.getStringExtra("title");