0

I used firebase cloud functions to the device to device notifications but notifications not working on versions below 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. please help me out.

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
  • Is your problem related to receiving push messages, or showing notifications? – Peter Bruins Apr 18 '18 at 11:41
  • Also, it looks like you mixed up the code for creating the channel with the code that creates the notification. – Peter Bruins Apr 18 '18 at 11:46
  • showing notifications is my problem and so how can I separate my code for channel and showing notifications.. –  Apr 18 '18 at 11:54
  • `firebase` handle `notificaton` own ! , can you post your error? – iamkdblue Apr 18 '18 at 12:15
  • I am not getting an error in my logcat. And even on firebase log it's showing notifications log but not generated on below oreo. –  Apr 18 '18 at 12:24

1 Answers1

-1

In Oreo Notification is showing using chanel id as in your code. But below oreo version chanel id is not required to use.

Check if your getting log while you receive notification from friebase. If you are getting log then notification functionality is working properly, you are not correctly notifying the device.

  • Yes, I am getting a log on firebase for notifications and I know there is some problem with my code to notify device but I am not able to resolve this. –  Apr 18 '18 at 11:59
  • Check if log is coming in android studio then check sdk version is >= 26 then execute your notification code else copy paste the same code from "MyFirebaseMessagingService.java" method "sendNotification(String message)" https://github.com/firebase/quickstart-android/tree/3a28699cb27d305fefb090d3e5fe15e80d319c4c/messaging – Sandeep Singh Apr 18 '18 at 12:46