firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
215 stars 35 forks source link

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

Closed sebastian-dudzic closed 3 months ago

sebastian-dudzic commented 4 years ago

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

google-oss-bot commented 4 years ago

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

paulinon commented 4 years ago

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.

sebastian-dudzic commented 4 years ago

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.

alf16d commented 4 years ago

I have the same problem. How to fix it?

alejobrainz commented 4 years ago

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

vzlomvl commented 4 years ago

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

wesclarkemag commented 4 years ago

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

JohannCaron commented 4 years ago

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(){ }

vzlomvl commented 4 years ago

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.

leynier commented 4 years ago

I have exactly the same problem

schemann commented 4 years ago

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

chandujr commented 4 years ago

Still occurring in 6.14.1.

lucasgaspar commented 3 years ago

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

chandujr commented 3 years ago

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

Afmj22 commented 3 years ago

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");
            }
 }
RobinopdeBeek commented 3 years ago

Thanks Johan, your workaround worked!

eXisting commented 3 years ago

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.

giangchau92 commented 3 years ago

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

visioncored commented 3 years ago

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:

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

p0w1nd commented 2 years ago

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)

anhnhgtv commented 2 years ago

Same problem 2021. This loops forever :(

anhnhgtv commented 2 years ago

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?

micsnz commented 2 years ago

@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

Vincze01 commented 2 years ago

@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:

HasithaCJ commented 2 years ago

@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

marcinwalus commented 2 years ago

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:

mgrogin commented 1 year ago

Any update on this?

FredGithub commented 1 year ago

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

JF47 commented 1 year ago

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

spikyworm5 commented 1 year ago

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

Any updates about this issue?

Jake-NSW commented 1 year ago

Oh well... they have deprecated Dynamic Links it looks like...

https://firebase.google.com/support/dynamic-links-faq

I don't think the issue will be getting fixed. 😢

argzdev commented 3 months ago

Hi folks, we'd like to inform you that the Firebase Dynamic Links service will be shutdown on August 25, 2025. In the meantime, only critical or security issues will be fixed in the SDK.

More at https://firebase.google.com/support/dynamic-links-faq