Android Notification.PRIORITY_MAX 已弃用 在顶部显示通知的替代方法是什么?

标签 android android-notifications

如何在顶部显示安卓通知? 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);

最佳答案

优先级最大 此常量在 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);

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

关于Android Notification.PRIORITY_MAX 已弃用 在顶部显示通知的替代方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46962253/

相关文章:

android - 处理 Activity 和 Thread 之间关系的常见做法是什么

android - 如何使用 Canvas 绘制不同图案的线条?

android - ionic 键盘事件未在 Android 上触发

java - 只要应用程序打开,AlarmManager 就会关闭

Android 通知内容不会显示

android - 房间 : Renaming Table doesn't update Foreign Key Table Reference

Android Galaxy S4 使用 values-large?

java - 打开通知后 fragment 不会更新

android - NotificationCompat 和 setFullScreenIntent()

Xamarin Forms Android 在关闭时不接收推送通知