Skip to content

Dynamic Links on Android with C++ SDK only received if App not started previously #20

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

Closed
ForestRingGames opened this issue Nov 23, 2017 · 3 comments

Comments

@ForestRingGames
Copy link

We've setup dynamic link creation both on iOS and Android with the Firebase Dynamic Link C++ SDK. All is working perfectly fine on iOS, links get received and the Listener is triggered whether the App is closed before or not. This is our Listener code:

void PlatformManager::OnDynamicLinkReceived(const firebase::dynamic_links::DynamicLink *dynamic_link)
{
        MLLOG("[PlatformManager] OnDynamicLinkReceived - Received link: %s", dynamic_link->url.c_str());
}

App Init:

#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
       
    firebase::AppOptions appOptions;
    _firebaseApp = firebase::App::Create(appOptions);

#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID

    firebase::AppOptions appOptions;
    _firebaseApp = firebase::App::Create(firebase::AppOptions(), JniHelper::getEnv(), JniHelper::getActivity());

#endif

    firebase::dynamic_links::Initialize(*_firebaseApp, this);

Also our manifest setup:

        <activity
            android:name="org.cocos2dx.cpp.AppActivity"
            android:screenOrientation="sensorPortrait"
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:host="towerduel.com" android:scheme="http"/>
                <data android:host="towerduel.com" android:scheme="https"/>
            </intent-filter>
        </activity>

On Android, the log is only triggered when the App was not open previously. If the App was open, then clicking the Link also does correctly open the App, but the listener is not triggered / no log ist printed.

Do you have any idea why this is happening and how we can also make the listener trigger if the app is already open like on iOS?

@stewartmiles
Copy link
Contributor

Unfortunately we can't hook the application lifecycle on Android (on iOS we use method swizzling on the app delegate) so you need to call dynamic_links::Fetch() when the app gains focus to get the link.

https://firebase.google.com/docs/reference/cpp/namespace/firebase/dynamic-links#namespacefirebase_1_1dynamic__links_1ad0a04de4c0b8c875bf6fe39fa90ea420

@ForestRingGames
Copy link
Author

Thank you so much, this works!

Really cool support here :)
In case you want to add it to the documentation, I followed these guides here:
https://firebase.google.com/docs/dynamic-links/android/receive
https://firebase.google.com/docs/dynamic-links/cpp/receive

Maybe it'd be cool to add this piece of info to these guides, so people will not make the same mistake in the future.

@johnb003
Copy link

A note was added to the bottom of:
https://firebase.google.com/docs/dynamic-links/cpp/receive

"Note: On Android you must also call Fetch() when the application gains focus in order for the listener to be triggered."

@firebase firebase locked and limited conversation to collaborators Oct 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants