Android Notification.PRIORITY_MAX is deprecated what is the alternative to show notification on top?
PRIORITY_MAX This constant was deprecated in API level 26. use IMPORTANCE_HIGH instead.
PRIORITY_MAX
int PRIORITY_MAX
This constant was deprecated in API level 26. use IMPORTANCE_HIGH instead.
Highest priority, for your application's most important items that require the user's prompt attention or input.
Constant Value: 2 (0x00000002)
// create ios channel
NotificationChannel iosChannel = new NotificationChannel(IOS_CHANNEL_ID,
IOS_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
iosChannel.enableLights(true);
iosChannel.enableVibration(true);
iosChannel.setLightColor(Color.GRAY);
iosChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
getManager().createNotificationChannel(iosChannel);
https://developer.android.com/reference/android/app/Notification.html#PRIORITY_MIN
In android O there was introduction of Notification channels. In particular you define Channel with constructor. In documentation you can see notion of importance and that is what replaces priority.
Starting from Android O (API 26) priority at notification level has been deprecated. It was replaced by importance at the channel level and the notifications must now be put in a specific channel.
If you are running on Android O or greater you have to create a channel and define the channel importance.
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
If you need to maintain the back compatibility with older Android version then you have to continue to define the priority at the notification level.
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
...
.setPriority(Notification.PRIORITY_MAX)
...
Unfortunately it generates the warning about PRIORITY_MAX deprecation.
It can be avoid using NotificationCompat version of the PRIORITY_MAX constant.
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
...
.setPriority(NotificationCompat.PRIORITY_MAX)
...