firebase-unity-sdk icon indicating copy to clipboard operation
firebase-unity-sdk copied to clipboard

The same received event of Dynamic Links is called every time after maximizing app

Open sebastian-dudzic opened this issue 5 years ago • 31 comments

Unity editor version: 2018.4.5f1 Firebase Unity SDK version: 6.6.0, 6.9.0, 6.10.0 (all not working) Firebase plugins in use (Auth, Database, etc.): Analytics, RemoteConfig, Crashlytics, DynamicLinks Additional SDKs you are using (Facebook, AdMob, etc.): Admob mediation, Facebook provider for Admob, Facebook SDK, Appsflyer, Android Native Pro, Platform you are using the Unity editor on (Mac, Windows, or Linux): Windows Platform you are targeting (iOS, Android, and/or desktop): Android Scripting Runtime (Mono, and/or IL2CPP): Mono and IL2CPP Dot.net: 4.x Devices: Xiaomi Mi 8, Google Pixel 4, Samsung S7, Samsung Note 4 Android version: from 6.0 to 10.0 (older not tested)

It's exactly the same bug as in https://github.com/firebase/quickstart-unity/issues/502

Steps to reproduce:

  1. Open App or do nothing
  2. Click dynamic link
  3. App is opened, link is correctly received
  4. Minimize app
  5. Maximize (but select app from background apps previews list, don't click on app icon, then it's working)
  6. Previously clicked link is received again (though nothing was clicked)

I have also tried clicking multiple times in different dynamic links in on app run. Behaviour is always the same. After maximize it fires only LAST clicked link. Not all. But expected behavior is to do nothing then.

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? Yes. Mono, Unity 2018.4.5f1, Firebase 6.10.0.

What's the issue repro rate? 100%

There is a video with bug using quickstarts project: https://drive.google.com/file/d/1BJF_fx9gGeEZNZMJM1c440NmBi4HP-pf/view?usp=sharing

sebastian-dudzic avatar Feb 04 '20 08:02 sebastian-dudzic

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Feb 04 '20 08:02 google-oss-bot

Thanks for reporting this @SebaDudzic. I was able to reproduce this issue on my end using the quickstart, so I've filed an internal bug report for this. I can't provide any timelines for the fix, so I'll leave this open.

paulinon avatar Feb 04 '20 13:02 paulinon

I'm glad you have managed to reproduce that. It's a big issue for us. We have to implement a workaround that is not going to work perfectly. It has UX disadvantages. So please keep me informed if any fix will be available.

sebastian-dudzic avatar Feb 04 '20 13:02 sebastian-dudzic

I have the same problem. How to fix it?

alf16d avatar Feb 24 '20 19:02 alf16d

We are experiencing the same, harming our ability to successfully use dynamic links for social sharing replays in our game.

alejobrainz avatar Mar 17 '20 12:03 alejobrainz

Hi @paulinon We have same issue. Do you have any ETA for fix of this issue? Thanks.

vzlomvl avatar Apr 13 '20 10:04 vzlomvl

We're also suffering from this issue. When will we see a fix?

wesclarkemag avatar Apr 21 '20 10:04 wesclarkemag

Same on our side. It seems clearing those Intent extras is enough to prevent the dynamic link to execute each time the app comes to the foreground:

AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
var intent = activity.Call<AndroidJavaObject>("getIntent");

intent.Call("removeExtra", "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA");
intent.Call("removeExtra", "com.google.android.gms.appinvite.REFERRAL_BUNDLE");

May be worth disposing those object, or enclosing them with using(){ }

JohannCaron avatar Apr 28 '20 16:04 JohannCaron

Hi @paulinon. This bug is blocker for us on Android. Information about ETA of the fix will allow us to decide should we move to another Deep Link solution or wait until the fix. Could you please provide any information about status of internal issue? Is it still Open or InProgress? Thanks.

vzlomvl avatar May 19 '20 07:05 vzlomvl

I have exactly the same problem

leynier avatar Jul 13 '20 21:07 leynier

Any ETA when to expect a Fix? Problem is still present in latest version...

schemann avatar Aug 19 '20 13:08 schemann

Still occurring in 6.14.1.

chandujr avatar Aug 29 '20 14:08 chandujr

Has anyone been able to solve this? It is solvable or we need just wait for the fix?

Edit: The solution give by Johan worked like a charm: https://github.com/firebase/firebase-unity-sdk/issues/364

lucasgaspar avatar Sep 23 '20 13:09 lucasgaspar

Not fixed yet. Johan's solution is what worked for me as well.

chandujr avatar Sep 23 '20 15:09 chandujr

The new AndroidJavaClass("com.unity3d.player.UnityPlayer") dosent exist when i run it. Update: After doing some more testing this is what worked for me:

using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) 
 {
            using (AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
            {
                var intent = activity.Call<AndroidJavaObject>("getIntent");
                intent.Call("removeExtra", "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA");
                intent.Call("removeExtra", "com.google.android.gms.appinvite.REFERRAL_BUNDLE");
            }
 }

Afmj22 avatar Nov 22 '20 01:11 Afmj22

Thanks Johan, your workaround worked!

RobinopdeBeek avatar Mar 08 '21 15:03 RobinopdeBeek

As a workaround for us that works on both Android and iOS I implemented it in the following way by using intermediate class for triggering deep links:

  1. Subscribe to Firebase Dynamic Links as you usually do
  2. In your delegate method for subscription immediately unsubscribe
  3. Subscribe to Unity's Application.deepLinkActivated with the method that should trigger "step 4"
  4. In the same delegate trigger your game logic that should happen by deep link open

Works with both deferred and regular deep links with no issues.

eXisting avatar Mar 19 '21 13:03 eXisting

Disappointed, this is version 7.2.0 now, but no one on Firebase team care about it.

giangchau92 avatar Jun 18 '21 11:06 giangchau92

The issue persists in v8.1.0. So, I tried a workaround provided by eXisting, worked for me initially :)

As a workaround for us that works on both Android and iOS I implemented it in the following way by using intermediate class for triggering deep links:

  1. Subscribe to Firebase Dynamic Links as you usually do
  2. In your delegate method for subscription immediately unsubscribe
  3. Subscribe to Unity's Application.deepLinkActivated with the method that should trigger "step 4"
  4. In the same delegate trigger your game logic that should happen by deep link open

Works with both deferred and regular deep links with no issues.

Nonetheless, the Dynamic Link was called again after the reopening the closed game app if:

  • The Dynamic Link was called after unsubscribing a method from the DynamicLinkReceived event delegate.

To fix this issue, just subscribe an empty method to DynamicLinks.DynamicLinkReceived after initially unsubscribing the original method based on eXisting's steps.

visioncored avatar Aug 12 '21 02:08 visioncored

Just want to report that I'm using Firebase 8.2.0 and encountering this same issue on Android. Unity 2019.4.

. My game displays an in-app message . Tap on the button => dynamic link is received (the dynamic link is configured on Firebase In-App Messaging section)

  • OnDynamicLink(object sender, EventArgs args) opens a web page with Application.OpenURL
  • Android browser is launched
  • I press the back key to go back to the game
  • The game is in the foreground for a second and it opens the browser again
  • Debug.Log shows that OnDynamicLink is called every time the game is back to foreground
  • This loops forever!!! 😱

p0w1nd avatar Sep 20 '21 15:09 p0w1nd

Same problem 2021. This loops forever :(

anhnhgtv avatar Sep 23 '21 14:09 anhnhgtv

The new AndroidJavaClass("com.unity3d.player.UnityPlayer") dosent exist when i run it. Update: After doing some more testing this is what worked for me:

using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) 
 {
            using (AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
            {
                var intent = activity.Call<AndroidJavaObject>("getIntent");
                intent.Call("removeExtra", "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA");
                intent.Call("removeExtra", "com.google.android.gms.appinvite.REFERRAL_BUNDLE");
            }
 }

What file can I add this code to?

anhnhgtv avatar Sep 23 '21 14:09 anhnhgtv

@JohannCaron 's solution doesn't seem to work for me. The dynamic links still fire again on focus. Maybe I'm implementing it wrong? This is my code:

private void StartDynamicLinks()
{
	DynamicLinks.DynamicLinkReceived += OnDynamicLinkReceived;
}

private void OnDynamicLinkReceived(object sender, EventArgs args)
{
	var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
	Debug.LogFormat("Received dynamic link {0}", dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);

	using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
	{
		using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
		{
			var intent = activity.Call<AndroidJavaObject>("getIntent");
			intent.Call("removeExtra", "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA");
			intent.Call("removeExtra", "com.google.android.gms.appinvite.REFERRAL_BUNDLE");
		}
	}

	// logic to handle link string goes here...
}

I'm using version 8.6.1 of the SDK on Unity 2020.3.16f1

cimved avatar Dec 12 '21 06:12 cimved

@JohannCaron 's solution doesn't seem to work for me. The dynamic links still fire again on focus. Maybe I'm implementing it wrong? This is my code:

private void StartDynamicLinks()
{
	DynamicLinks.DynamicLinkReceived += OnDynamicLinkReceived;
}

private void OnDynamicLinkReceived(object sender, EventArgs args)
{
	var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
	Debug.LogFormat("Received dynamic link {0}", dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);

	using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
	{
		using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
		{
			var intent = activity.Call<AndroidJavaObject>("getIntent");
			intent.Call("removeExtra", "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA");
			intent.Call("removeExtra", "com.google.android.gms.appinvite.REFERRAL_BUNDLE");
		}
	}

	// logic to handle link string goes here...
}

I'm using version 8.6.1 of the SDK on Unity 2020.3.16f1

I use the same code and it works for me. So there should be no problem with implementation. I'm using:

  • Firebase 8.1.0
  • Unity 2020.3.15f2
  • Samsung Galaxy S7
  • Android 8.0.0

Vincze01 avatar Dec 15 '21 12:12 Vincze01

@JohannCaron 's solution doesn't seem to work for me. The dynamic links still fire again on focus. Maybe I'm implementing it wrong? This is my code:

private void StartDynamicLinks()
{
	DynamicLinks.DynamicLinkReceived += OnDynamicLinkReceived;
}

private void OnDynamicLinkReceived(object sender, EventArgs args)
{
	var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
	Debug.LogFormat("Received dynamic link {0}", dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);

	using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
	{
		using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
		{
			var intent = activity.Call<AndroidJavaObject>("getIntent");
			intent.Call("removeExtra", "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA");
			intent.Call("removeExtra", "com.google.android.gms.appinvite.REFERRAL_BUNDLE");
		}
	}

	// logic to handle link string goes here...
}

I'm using version 8.6.1 of the SDK on Unity 2020.3.16f1

This work for me too

HasithaCJ avatar Jan 26 '22 05:01 HasithaCJ

Hello. I used a solution suggested by @JohannCaron to clear "extra" and it was working correctly. But this solution no longer works - after opening my app with link, I'm displaying form to the user and after closing keyboard "OnDynamicLinkReceived" is fired again.

I was trying to use this code to check if "extras" exist but both values are false.

var hasExtraDYNAMIC_LINK_DATA = intent.Call<bool>("hasExtra", "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA");
var hasExtraREFERRAL_BUNDLE = intent.Call<bool>("hasExtra", "com.google.android.gms.appinvite.REFERRAL_BUNDLE");

I suspect that those extras names changed but have no idea how to list those extras.

My setup:

  • Firebase 9.4.0
  • Unity 2021.3
  • Android 12.0
  • Samsung A53

marcinwalus avatar Sep 01 '22 14:09 marcinwalus

Any update on this?

mgrogin avatar Oct 26 '22 12:10 mgrogin

Sometimes I get the feeling Google is about to shutdown Firebase as a whole... There's no way such a trivial bug is still happening after almost 3 years

FredGithub avatar Oct 27 '22 16:10 FredGithub

@paulinon How in the world is this still an active problem with no official solution!?!? This is insane, and needs to be fixed.

JF47 avatar Mar 16 '23 22:03 JF47

Still happening. Android 13. Firebase 10.7.0. Unity 2021.3.24f1.

Any updates about this issue?

spikyworm5 avatar May 09 '23 07:05 spikyworm5