【问题标题】:FireBase Cloud Messaging - how to open a link instead of Activity from notification in UnityFireBase Cloud Messaging - 如何在 Unity 中从通知中打开链接而不是 Activity
【发布时间】:2019-07-15 03:19:13
【问题描述】:

我在 Unity 中使用 FireBase 云消息传递。当用户单击来自 FireBase Cloud Messaging 的到达消息时,我想打开一个链接。

在 Firebase 面板中,我将带有 URL 值的自定义数据“click_action”设置为消息,并在单击 OnMessageReceived 方法中的通知时收到它:

public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
{
    Debug.Log("Received Data: " + e.Message.Data["click_action"]);        
}

当我添加类似

的代码时
Application.OpenURL(e.Message.Data["click_action"]);

在 OnMessageReceived 中,链接会打开,但应用程序也会在点击收到的通知时打开。

Unity中点击FCM消息时如何防止应用打开?

谢谢。

【问题讨论】:

    标签: android firebase unity3d firebase-cloud-messaging


    【解决方案1】:

    您尝试过 ACTION_VIEW Intent 吗?

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
    
        String message = remoteMessage.getData().get("click_action");
        String url = "http://your.url.here";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }
    

    【讨论】:

    • 感谢您的回答,但我在 Unity 游戏引擎中使用 FCM,而不是在 android 本机中。
    • @user1579019你有什么解决办法吗?我也在找一样的。
    猜你喜欢
    • 1970-01-01
    • 2020-08-25
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 2019-02-10
    相关资源
    最近更新 更多