简体   繁体   English

当应用程序在后台或被杀死时,如何在收到通知时启动我的应用程序或活动?

[英]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.

相关问题 在后台收到通知时,如何让我的android应用执行代码? - How can I get my android app to execute code when a notification is received when it's in background? ¿ 如何在后台启动我的应用程序或活动? - ¿How can i launch my app or an activity in background? 应用程序关闭或被杀死时未收到 Android FCM 通知 - Android FCM notification is not received when app is close or Killed 即使应用程序被杀死,我怎样才能让我的应用程序运行? 从最近的应用程序中删除时在某种意义上被杀死 - How can i make my app run even when app is killed? killed in the sense when it is removed from recent apps Android - 当收到推送通知 FCM 时,如何更新我的活动中的数据或 UI? - Android - How can I update data or UI in my Activity when Push Notification FCM is received? 应用程序被杀死时没有收到通知 - Not receiving notification when the app is killed 在后台启动应用以管理通知 - Launch app on background for manage notification 应用程序被杀死时后台TimerTask被杀死 - Background TimerTask gets killed when app is killed 在Android设置应用程序图标时的应用程序图标上的徽章编号或在接收Facebook应用程序等通知时被杀死 - On Android setting badge number on app icon when app is in background or killed when receiving notification like facebook app 在Google Play商店中更新我的应用程序时,如何保持我的应用程序通知显示? - How can I keep my app's notification displayed when my app is updated on Google Play store?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM