How can I open a specific scene from the firebase cloud messaging on click in Unity C#

Viewed 246

I am trying to make a Unity app in which firebase is sending notification to both android and iOS. but I want to open a specific scene when someone click on the notification. I don't have any idea how to do this.

2 Answers
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    var intent = currentActivity.Call<AndroidJavaObject>("getIntent");
    var extras = GetExtras(intent);
    var sceneToLoad = GetProperty(extras, "<key to load in string>");
    var currentScene = SceneManager.GetActiveScene();

GetExtras() function

    private static AndroidJavaObject GetExtras(AndroidJavaObject intent)
{
    AndroidJavaObject extras = null;

    try
    {
        extras = intent.Call<AndroidJavaObject>("getExtras");
    }
    catch (Exception e)
    {
        Debug.LogError("firebaseScript.GetExtras()->" + e.Message);
    }

    return extras;
}

GetProperty function

    private static string GetProperty(AndroidJavaObject extras, string name)
{
    var s = string.Empty;
    try
    {
        s = extras.Call<string>("getString", name);
    }
    catch (Exception e)
    {
        Debug.LogError("firebaseScript.GetProperty() throws ->" + e.Message);
    }

    return s;
}
Related