不推荐使用Android Notification.PRIORITY_MAX什么是在顶部显示通知的替代方法?

Ank*_*oor 9 android android-notifications

如何在顶部显示Android通知? setPriority(Notification.PRIORITY_MAX)

作为Notification.PRIORITY_MAX被弃用的替代方案是什么?

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);
Run Code Online (Sandbox Code Playgroud)

Aka*_*mar 8

PRIORITY_MAX此常量在API级别26中已弃用.请改用IMPORTANCE_HIGH.

PRIORITY_MAX

int PRIORITY_MAX

此常量在API级别26中已弃用.请改用IMPORTANCE_HIGH.

最高优先级,适用于需要用户及时关注或输入的应用程序最重要的项目.

常数值: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);
Run Code Online (Sandbox Code Playgroud)

https://developer.android.com/reference/android/app/Notification.html#PRIORITY_MIN


Jak*_*ieł 4

在android O中引入了通知通道。特别是,您使用constructor定义 Channel 。在文档中,您可以看到重要性的概念,这就是取代优先级的概念。