I have a requirement for my app. I have to launch my app when I received a Notification (specific notification type) when my app is in background or killed state. I didn't find any solution for background. I'm using FCM for notifications.
Actually my app support calling functionality from web side to mobile and when admin initiate call then I received a FCM push notification. when my app is foreground than it's work fine but when it is in background, than I received notification but for launch app I have to click on notification. but I need to launch app immediately. Have any one have any solution?
Try this one.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
startActivity(new Intent(this, MainActivity.class));
}
}
Use your app server and FCM server API: Set the data key only. Can be either collapsible or non-collapsible.
If you are sending the notification from console, then use the particular key to send the notification from the Advanced Option features.
if (getIntent().getExtras() != null) {
// Call your NotificationActivity here..
Intent intent = new Intent(MainActivity.this, NotificationActivity.class);
startActivity(intent);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.