Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onDeeplink() called too early on Android #11

Open
Daniel-Dobson opened this issue Jan 24, 2018 · 4 comments
Open

onDeeplink() called too early on Android #11

Daniel-Dobson opened this issue Jan 24, 2018 · 4 comments

Comments

@Daniel-Dobson
Copy link

Hi, thanks for the knowledge and code you have shared 👍

I have encountered an issue where if I use a deep link to start my app on Android, the intent parameters that I pass will not 'make it through' to the app, when it is started 'from cold'. If however they app is already running, and I click the same deep link, then all 3 of the parameters in my href link reach the app.

I think this may be a timing issue with onDeeplink() being called before the Unity App has fully loaded? I think my parameters and scheme must be correct as they do indeed reach the app and get displayed if it is already running. They are in the following format:

MyApp

Thanks in advance,

@Daniel-Dobson
Copy link
Author

This may relate to the

com.unity3d.player.UnityPlayer.UnitySendMessage(gameObject, deeplinkMethod, deeplink);

method, I am investigating this possibility.

@Daniel-Dobson
Copy link
Author

Daniel-Dobson commented Jan 25, 2018

Update - As a workaround to this problem I am using the following, called from Start():

#if UNITY_ANDROID
    private void RetreiveDeeplinkOnAndroid()
    {
#if !UNITY_EDITOR
        AndroidJavaClass unityPlayer         = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject currentActivity    = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject intent             = currentActivity.Call<AndroidJavaObject>("getIntent");
        string dataString                    = intent.Call<string>("getDataString");
        if (dataString.Length > 0)
        {
            decodedDeeplink = WebUtils.DecodeUrlString(dataString);			
        }
#endif
    }
#endif

It fixes the issue for me, but I still use onDeepLink() on Android for when the App is already running, to avoid having to continuously poll getDataString() while the app is running in case it has changed.

Cheers

@kevinvenclovas
Copy link

@Daniel-Dobson
App crash if you start the app without a deep link Unity 2017.3.03f -> solution add a try catch

@Daniel-Dobson
Copy link
Author

Ah interesting have not tried it with this version of Unity yet - where did you place the try/catch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants