android - FireBase Cloud Messaging - 如何从 Unity 中的通知打开链接而不是 Activity

标签 android firebase unity-game-engine firebase-cloud-messaging

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

在 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消息时如何防止应用程序打开?

谢谢。

最佳答案

您尝试过 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);
}

关于android - FireBase Cloud Messaging - 如何从 Unity 中的通知打开链接而不是 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54803205/

相关文章:

android - Android 项目的 Maven 原型(prototype)

android - 将 ImageReader 和 SurfaceTexture 与 Android Camera2 输出同步

ios - Firebase keepSynced 不会立即同步数据

javascript - 如何通过推送生成Firebase增量计数器

ios - Firebase Firestore 在同一应用中使用两个不同的实例

c# - 如何用不同大小的四边形填充程序生成的网格?

unity-game-engine - Unity 重命名公共(public)字段以保留分配

Android 应用错误 : W/ResourceType( 8276): ResXMLTree_node header size 0 is too small

android - 在 Android 中调用 Web API 并接收返回值

android - 在 Android 和 iOS 上的 Unity 中录制屏幕视频的最佳方式?