0

我在设备上使用了 Firebase 云功能到设备通知,但通知在低于 oreo 的版本上不起作用。

private void sendNotification1(String notificationTitle, String notificationBody) {
    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);
    PendingIntent pendingIntent1 = PendingIntent.getBroadcast(this, 0,new Intent(this, MyReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
    RemoteInput remoteInput = new RemoteInput.Builder(NOTIFICATION_REPLY)
            .setLabel("Respond to Message")
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(android.R.drawable.ic_delete,
                    "Reply Now...", pendingIntent1)
                    .addRemoteInput(remoteInput)
                    .build();

在这里,我正在为奥利奥创建通知通道

 NotificationChannel notificationChannel = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        notificationChannel = new NotificationChannel(CHANNEL_ONE_ID,
                CHANNEL_ONE_NAME, NotificationManager.IMPORTANCE_HIGH );

        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.setShowBadge(true);
        notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ONE_ID)
            .setAutoCancel(true)   //Automatically delete the notification
            .setSmallIcon(R.mipmap.ic_launcher)//Notification icon
            .addAction(action)
            .addAction(R.drawable.accept, "ACCEPT", pendingIntent)
            .addAction(R.drawable.delete, "DECLINE", pendingIntent)
            .setContentIntent(pendingIntent)
            .setContentTitle(notificationTitle)
            .setContentText(notificationBody)
            .setSound(defaultSoundUri);


    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        notificationManager.createNotificationChannel(notificationChannel);
    }
    notificationManager.notify(1, notificationBuilder.build());
}

我也提到了 Manifest 中的条目。并且在 oreo 上正确接收通知,但在 oreo 版本以下通知是不可见的。请帮帮我。

4

1 回答 1

-1

在 Oreo 通知中显示使用 chanel id 作为您的代码。但奥利奥以下版本不需要使用chanel id。

当您收到来自 friebase 的通知时,检查您的获取日志。如果您正在获取日志,则通知功能正常工作,您没有正确通知设备。

于 2018-04-18T11:52:18.607 回答