java - 通知 LED 灯未亮起

标签 java android firebase-cloud-messaging android-notifications

我几乎尝试了此处发布的所有修复,但此代码根本不会打开通知 LED。

public void onMessageReceived(RemoteMessage remoteMessage) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String channelId = getString(R.string.defaultChannelId);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this,channelId)
                    .setLights(Color.RED,200,1000)
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setAutoCancel(true)
                    .setDefaults(NotificationCompat.DEFAULT_ALL)
                    .setContentTitle(remoteMessage.getNotification().getTitle())
                    .setContentText(remoteMessage.getNotification().getBody())
                    .setSmallIcon(R.drawable.omega_icon)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

    Notification notification = notificationBuilder.build();
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(channelId,
                "Channel human readable title",
                NotificationManager.IMPORTANCE_DEFAULT);
        channel.enableLights(true);
        channel.setLightColor(0xFFFFFFFF);
        notificationManager.createNotificationChannel(channel);
    }
    notificationManager.notify(1, notification);
}

我正在从 Firebase 发送通知,除了 LED 灯外,一切都工作正常。来自其他应用程序的 LED 通知工作正常。

最佳答案

在 Oreo/API 26 之后,您无法更改 channel 颜色通知。

developer.android.com

关于java - 通知 LED 灯未亮起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58247476/

相关文章:

javascript - 按客户端过滤网络通知

firebase - flutter :FlutterFcmService - 致命:找不到回调

android - 为什么从导航组件版本 1.0.0-alpha09 中删除了 addDefaultArguments()?从 Activity 将 arg 传递给 StartDestination 的 WorkAround 是什么?

android - 重新创建 Activity 并传递参数

java - 在NotificationListenerService中过滤应用程序

Java 9 Eclipse 4.7 可移植导出错误 "resource not found", "Could not find main method from given launch configuration."

android adb通过adb打开wifi

android - 当应用程序处于后台状态时,Google FCM getIntent 不返回预期数据

java - Spring MVC - 如何在 Rest Controller 中以 JSON 形式返回简单字符串

java - 滚动 JLayer 的行为与它应该替换的滚动 JPanel 不同