i am working on android app which receive FCM (fire base messaging clouding), when the app is in the background or it is off android system recieve the notification and display it correctly, but the notification is not displayed when the app become in the foreground, i have checked the service which extends FirebaseMessagingService, it is not running and i dont know how to make it run.
the service code:
public class MyService extends FirebaseMessagingService {
public MyService() {
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}
the manifest code:
<service android:name=".MyService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
the main activity code:
startService(new Intent(this,MyService.class));
Firebase Cloud Messaging offers different message types to use. These are:
FirebaseMessagingService
. If you handle a data message, you're still able to manually show a notificationNow more specifically
The type of the message depends on what's inside of the object of your message. you should care about notification
and data
fields inside.
If you specify the notification
object (it's a title and a body of your push notification) and don't include the data
object - then your message type is notification
If you do vice versa, specify only data
object, then the type is data
And combining both types leads to the last type
So if you you want to simply show some information using push notification, consider using the notification type.
You can find more information on the official documentation page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With