1

First and foremost I read a similar question about this issue, but It didn't solve my issue. This is the question FCM question

I have implemented almost each and everything, but I don't know if I have left something out. I tested the notifications on the API 27 and 28 version devices but it didn't work out. Even the logs aren't displaying in the onMessageReceived(), I checked the google-service.json file and seems okay, so am wondering what is the problem ?

Below is my FirebaseInstance class implementation

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

        Log.d("No messages why ?", "From: " + remoteMessage.getFrom());

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d("Horray", "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }


        showNotification(remoteMessage.getNotification().getTitle(),
                remoteMessage.getNotification().getBody());
    }


private void showNotification(String title, String body) {

        NotificationManager notificationManager = (NotificationManager)
                getSystemService(Context.NOTIFICATION_SERVICE);
        String NOTIFICATION_CHANNEL_ID = "huxy.fcm.com.newfcmapp";

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){

            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                   "Notification",NotificationManager.IMPORTANCE_DEFAULT );

            notificationChannel.setDescription("EDMT Channel");
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.BLUE);
            notificationChannel.setVibrationPattern(new long[]{0,1000,500,1000});
            notificationChannel.enableLights(true);
            notificationManager.createNotificationChannel(notificationChannel);
        }

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

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

        notificationManager.notify(new Random().nextInt(), notificationBuilder.build());

    }

The full class can be viewed from the GitHub link here Firebase Messaging instance class

Then my Manifest file can also be accessed from here : Manifest file

You can also navigate my entire project to see if I have done any error, the project is just testing firebase cloud messaging. There's no other functionality.

Below is the link to the project :

FCM sample project

This is the console I use to send messages:

enter image description here

This is where I placed my device token :

enter image description here

Idris Stack
  • 382
  • 1
  • 5
  • 24
  • Is the device token correct? Please add another Service for the token generation. And register that in the manifest. It will extend FirebaseInstanceIdService – Pronoy999 Jan 27 '19 at 15:45
  • public class FirebaseIdGenerator extends FirebaseInstanceIdService { private String TAG_CLASS = FirebaseIdGenerator.class.getSimpleName(); @Override public void onTokenRefresh() { String token = FirebaseInstanceId.getInstance().getToken(); Messages.logMessage(TAG_CLASS, "TOKEN *** - " + token); //sendTokenToServer(); } } – Pronoy999 Jan 27 '19 at 15:49
  • Use this for help and reference. https://github.com/udacity/AdvancedAndroid_Squawker/blob/TFCM.03-Solution-GetInstanceIdToken/app/src/main/java/android/example/com/squawker/fcm/SquawkFirebaseInstanceIdService.java – Pronoy999 Jan 27 '19 at 15:52
  • Hey, I got the reason as to why it wasn't working. My emulator's google play service wasn't up to date. – Idris Stack Jan 27 '19 at 16:31

0 Answers0