繁体   English   中英

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

[英]how can i launch my app or an activity on notification received when app is in background or killed?

我对我的应用程序有要求。 当我的应用程序处于后台或终止状态时收到通知(特定通知类型)时,我必须启动我的应用程序。 我没有找到任何背景解决方案。 我正在使用 FCM 进行通知。

实际上,我的应用程序支持从 Web 端到移动设备的呼叫功能,当管理员发起呼叫时,我收到了 FCM 推送通知。 当我的应用程序在前台时它工作正常但当它在后台时我收到通知但要启动应用程序我必须单击通知。 但我需要立即启动应用程序。 有没有人有任何解决方案?

试试这个。

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        startActivity(new Intent(this, MainActivity.class));
    }
}

使用您的应用服务器和 FCM 服务器 API:仅设置数据密钥。 可以是可折叠的或不可折叠的。

如果您从控制台发送通知,则使用特定键从高级选项功能发送通知。

   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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM