[英]how can i launch my app or an activity on notification received when app is in background or killed?
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.
我正在使用 FCM 进行通知。
Actually my app support calling functionality from web side to mobile and when admin initiate call then I received a FCM push notification.实际上,我的应用程序支持从 Web 端到移动设备的呼叫功能,当管理员发起呼叫时,我收到了 FCM 推送通知。 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.使用您的应用服务器和 FCM 服务器 API:仅设置数据密钥。 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.