Skip to content Skip to sidebar Skip to footer

Android Firebase Notification Message Received But Notification Prompt Is Not Showing?

I have followed this tutorial and when I try to send a message from Firebase console, onMessageReceived were called and createNotification were performed, no notification prompt sh

Solution 1:

Finally found that the notification were actually only appeared on the android drop down menu instead of popping up due to my device is running Android 4. I test again with Android 5 device and the notification pop up just like the tutorial.


Solution 2:

Maybe you were missing notification notify.
Please try bellow code. it's working properly

//This method is only generating push notification
    //It is same as we did in earlier posts
    private void sendNotification(RemoteMessage remoteMessage) {
        Intent resultIntent = new Intent(this, MenuBarActivity.class);
        resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        HashMap<String, String> dataMap = new HashMap<String, String>(remoteMessage.getData());
        resultIntent.putExtra(Constant.KEY_MESSAGE_BODY, dataMap);
        resultIntent.putExtra(Constant.KEY_IS_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(getString(R.string.app_name))
                .setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getData().get(Constant.KEY_BODY)))
                .setContentText(remoteMessage.getData().get(Constant.KEY_BODY))
                .setAutoCancel(true)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setSound(defaultSoundUri);

//        if (!BaseActivity.isInForeground()) {
        notificationBuilder.setContentIntent(pendingIntent);
//        }
        // Generate ID
        long time = new Date().getTime();
        String tmpStr = String.valueOf(time);
        String last4Str = tmpStr.substring(tmpStr.length() - 5);
        int notificationId = Integer.valueOf(last4Str);

        // Sets an ID for the notification
//            int notificationId = Constant.NOTIFICATION_ID;

        // Gets an instance of the NotificationManager service
        NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        // Builds the notification and issues it.
        mNotifyMgr.notify(notificationId, notificationBuilder.build());
    }

Post a Comment for "Android Firebase Notification Message Received But Notification Prompt Is Not Showing?"