Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Get intent data string on every app start also with com.google.firebase.MessagingUnityPlayerActivity

Discussion in 'Scripting' started by AntiHero85, Dec 15, 2020.

  1. AntiHero85

    AntiHero85

    Joined:
    Dec 15, 2020
    Posts:
    2
    Hello,

    I´m struggling with the following problem. I open my Unity Android App with an intent from a link. Everything works fine. But I also would like to get the intent data string to redirect to correct screen in my App. I get the intent data string only on first start of the app. If I pause the app and resume with the link, the intent data string wont be updated. Following is the code of the intent filter in the android manifest. I can´t change the activity to com.unity3d.player.UnityPlayerActivity because of known issues when receiving notification data payloads in the background.
    Code (XML):
    1. <activity android:name="com.google.firebase.MessagingUnityPlayerActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    2.       <intent-filter>
    3.         <action android:name="android.intent.action.MAIN" />
    4.         <category android:name="android.intent.category.LAUNCHER" />
    5.       </intent-filter>
    6.       <intent-filter>
    7.         <action android:name="android.intent.action.VIEW"></action>
    8.         <category android:name="android.intent.category.DEFAULT"></category>
    9.         <category android:name="android.intent.category.BROWSABLE"></category>
    10.         <data
    11.         android:host="com.urltoopen.app"
    12.         android:scheme="https"></data>
    13.       </intent-filter>
    14.       <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    15.     </activity>
    In Unity I try to get the intent data string with following code:
    Code (CSharp):
    1. AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    2. //AndroidJavaClass jc = new AndroidJavaClass("com.google.firebase.MessagingUnityPlayerActivity");
    3. AndroidJavaObject context = jc.GetStatic<AndroidJavaObject>("currentActivity");      
    4. AndroidJavaObject intent = context.Call<AndroidJavaObject>("getIntent");
    5. Debug.Log($"Intent data string: {intent.Call<string>("getDataString")}");
    If I try to get the intent with the class com.google.firebase.MessagingUnityPlayerActivity as shown in line two I´ll get the error: there is no field "currentActivity" ...

    I´ll get the intent data string on the first start of the app. But not when resuming the app from background. Is there any other solution to get the intent data string on every start of the app?
    I´m looking forward to any suggestion, thanks a lot.
     
  2. james_unity54

    james_unity54

    Joined:
    Feb 23, 2018
    Posts:
    1
    Hey did you ever find a solution to this? I'm having the same issue.
     
  3. AntiHero85

    AntiHero85

    Joined:
    Dec 15, 2020
    Posts:
    2
    No sorry, I didn´t found a good solution yet.