【问题标题】:start activity from FCM when the Application is dead?当应用程序死亡时从 FCM 开始活动?
【发布时间】:2016-08-30 12:24:28
【问题描述】:

我正在使用 Firebase 云消息传递,并希望显示通话。 Firebase 消息已成功接收并且通知部分有效,但当应用程序已关闭且 DEAD

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    if(remoteMessage.getNotification().getBody().equals("showcall")) {
            Log.e(TAG,"Want to start activity");
            Intent intent = new Intent(this,ShowCallActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
        }
    }

}
// 

显示通知,但不会打开死应用。

【问题讨论】:

标签: android android-intent firebase firebase-cloud-messaging


【解决方案1】:

我是编程新手,终于找到了关于这个问题的一点线索。新版本的 android (MarshMallow) 有一个新的限制,即当应用死机时限制从应用打开活动。我不能解释太多,但你可以在这里阅读 https://developer.android.com/guide/components/activities/background-starts?authuser=1 如果授予此权限,则每个意图都可以正常工作。您可以查看任何 VOIP 应用程序,例如 WhatsApp。该应用程序已在用户不知情的情况下授予此权限。希望对您有所帮助

【讨论】:

    【解决方案2】:

    为了让它工作,我不得不使用数据消息并将"notification" 键保持为空。

    来自 firebase 文档的示例。

    {
        "message":{
            "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
            "data":{
                 "Nick" : "Mario",
                 "body" : "great match!",
                 "Room" : "PortugalVSDenmark"
            }
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多