Android O通知导致setLights()不推荐使用,setLightColor()闪烁?

时间:2018-03-15 18:02:46

标签: java android android-notifications android-8.0-oreo

我有这段代码:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("test", getString(R.string.notification_channel_news), NotificationManager.IMPORTANCE_HIGH);

        channel.enableLights(true);
        channel.setLightColor(Color.YELLOW);
        channel.enableVibration(true);
        channel.setVibrationPattern(pattern);
        channel.setImportance(NotificationManager.IMPORTANCE_HIGH);
        channel.setDescription("desc");

        Log.e("notif", channel.shouldShowLights() + "");

        if (notificationManager != null) {
            notificationManager.createNotificationChannel(channel);
        }
    }
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "test")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setPriority(2)
            .setContentTitle(messageTitle)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
            .setVibrate(pattern)
            .setLights(Color.YELLOW,5,5)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    Notification not = notificationBuilder.build();

如何设置像被删除的.setLights(Color.YELLOW,5,5)一样的延迟?因为在Android O上,.setLights(Color.YELLOW,5,5)根本不起作用。

1 个答案:

答案 0 :(得分:0)

您不能-似乎Android API不再允许自定义闪烁模式。