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 :
This is the console I use to send messages:
This is where I placed my device token :