简体   繁体   English

在以下oreo的Android版本上无法接收通知

[英]Not able to receive notifications On Android version below oreo

I used firebase cloud functions to the device to device notifications but notifications not working on versions below oreo. 我将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();

Here I am creating notification channel for oreo 我在这里为奥利奥创建通知渠道

 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());
}

I also mentioned the entry in Manifest too. 我也提到了清单中的条目。 And receiving notifications on oreo properly but below oreo version notifications are invisible. 正确接收到oreo上的通知,但低于oreo版本的通知是不可见的。 please help me out. 请帮帮我。

In Oreo Notification is showing using chanel id as in your code. 在Oreo中,通知显示使用代码中的chanel ID。 But below oreo version chanel id is not required to use. 但在oreo版本以下,无需使用chanel ID。

Check if your getting log while you receive notification from friebase. 在收到来自friebase的通知时,检查是否获取日志。 If you are getting log then notification functionality is working properly, you are not correctly notifying the device. 如果您正在获取日志,则通知功能正常运行,则表示未正确通知设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM