0

Here is the code for the Firebase Messaging service:

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

To show notification in foreground:

    private void showNotification(String title, String body) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        String NOTIFICATION_CHANNEL_ID = "com.shijan.qrscannerict.test";

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);

        notificationBuilder.setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.ict_logo)
                .setContentTitle(title)
                .setContentText(body)
                .setContentInfo("Info");

        notificationManager.notify(new Random().nextInt(), notificationBuilder.build());
    }
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
  • If there's a crash then there's a crash log and there are some instructions for reading it in [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this). You can also set a break point into `showNotification()` and debug it step by step to study the states of the variables and see where it crashes. At the moment there's not much information for anyone to comment your problem unless of course something is evident just by reading the code. – Markus Kauppinen Nov 20 '18 at 14:32
  • @MarkusKauppinen Thanks for the suggestion. The issue is finally fixed. – Shijan Shrestha Nov 20 '18 at 17:40

1 Answers1

0

The issue is fixed. The problem was that the app(Marshmallow) was not being able to extract the notification icon that I set. The app worked when I created a new image asset for the notification icon in the res directory.