Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Notification.PRIORITY_MAX is deprecated what is the alternative to show notification on top?

How to show android notification on top? setPriority(Notification.PRIORITY_MAX)

as Notification.PRIORITY_MAX is deprecated what is the alternative?

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setContentIntent(pendingIntent)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Notification Title")
                .setContentText("Notification Text")
                .setPriority(Notification.PRIORITY_MAX)
                .setAutoCancel(true);
like image 808
Ankush Kapoor Avatar asked Oct 26 '17 19:10

Ankush Kapoor


People also ask

How do I make notifications appear at the top?

Go to Settings > System > Notifications & actions‌ , under Get notifications from these senders select the app, and then under Priority of notifications in action center select Top.

How do I keep notifications on top of Android?

Swipe down to see notifications. Swipe a conversation partially to the left until you see the Settings icon (shaped like a gear). Tap the Settings icon. Tap the priority level you want: Priority, Default, or Silent.

How do I make Android notifications pop up?

At the top of the screen, turn Notifications ON. 4. Under Notifications, tap Display pop-ups when screen is on or Display pop-ups when screen is off to turn these settings ON or OFF.

How do I use NotificationCompat?

To make this possible, Android N uses the existing NotificationCompat. Builder. setGroup() method. Users can expand each of the notifications, and perform actions such as reply and dismiss on each of the notifications, individually from the notification shade.


2 Answers

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

like image 94
Akash kumar Avatar answered Oct 19 '22 19:10

Akash kumar


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.

like image 24
Jakub Szczygieł Avatar answered Oct 19 '22 19:10

Jakub Szczygieł