I am having an issue with FireBase Cloud Messaging in which I get the Token from the device and send the notification test through the Google Firebase notification console h
In my case, I noticed mergedmanifest was missing the receiver. So I had to include:
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
private void sendNotification(String message) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
int requestCode = 0;
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.URI_COLUMN_INDEX);
NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText(message)
.setColor(getResources().getColor(R.color.colorPrimaryDark))
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("FCM Message")
.setContentText("hello").setLargeIcon(((BitmapDrawable) getResources().getDrawable(R.drawable.dog)).getBitmap())
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(((BitmapDrawable) getResources().getDrawable(R.drawable.dog)).getBitmap()))
.setAutoCancel(true)
.setSound(sound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, noBuilder.build());
I faced the same issue of Firebase cloud messaging not received by device.
In my case package name defined on Firebase Console Project was diferent than that the one defined on Manifest & Gradle of my Android Project.
As a result I received token correctly but no messages at all.
To sumarize, it's mandatory that Firebase Console package name and Manifest & Gradle matchs.
You must also keep in mind that to receive Messages sent from Firebase Console, App must be in background, not started neither hidden.
"You must also keep in mind that to receive Messages sent from Firebase Console, App must be in background, not started neither hidden." --- According to @Laurent Russier's comment.
I never got any message from Firebase, until i put my app in the background.
This is true only on usb connection for emulator you get notification in foreground as well
You have placed your service outside the application tag. Change bottom to this.
<service
android:name=".NotificationGenie">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
In my case, I manually killed some google play services and forgot about it.
Later, I have to restart the device, after that I can receive notification without any problem.