Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Dynamic Link open specific Activity

Tags:

I implemented Firebase Dynamic links (which are great!) on my iOS app and am now doing the same job on Android. I managed to launch my Android app by clicking the dynamic URL, but I can't open it on another activity than my launcher activity.

Here is my manifest.xml file :

    <activity android:name=".Activity.SplashActivity"
        android:theme="@style/SplashTheme"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".Activity.RouteListActivity"
        android:screenOrientation="portrait">
        <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="mywebsite.com" android:scheme="http"/>
            <data android:host="mywebsite.com" android:scheme="https"/>
            <data
                android:host="myapp.app.goo.gl/"
                android:scheme="https" />
        </intent-filter>
    </activity>

When I click the URL, browser opens and redirects to my app but it opens on SplashActivity and not on RouteListActivity as expected.

Do I miss something?

Thank you

like image 803
GrayFox Avatar asked Dec 13 '17 13:12

GrayFox


1 Answers

Well, I guess I found a simple workaround that's able to overcome this problem.

I reminded of an app I developed in which the dynamic links work well in previous versions and I just tested them again to confirm (here is a sample dynamic link to demonstrate it really works); so I went to its manifest to know what I did back then.

Basically, it's important to add an android:autoVerify=true to the intent filter like this:

        <intent-filter
            android:autoVerify="true">

It'll make a request to verify app links as you can read here in order to understand it better.

As this solution only works from API 23 on, I suggest to add tools:targetApi="23" too as "this tells the tools that you believe this element (and any children) will be used only on the specified API level or higher" and to avoid an unwanted Lint highlight then.

So, the best way to deal with this is by adding the following code:

        <intent-filter
            android:autoVerify="true"
            tools:targetApi="23">

It's important to mention that "set as default" options from the user end might overlook this option depending on the way users use the link because it may appear a popup offering choices about how to handle the link and it can be somehow misleading (the two options look the same considering my app and device at least).

In the sample manifest file present in this question, it would look like this:

<activity android:name=".Activity.SplashActivity"
    android:theme="@style/SplashTheme"
    android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<activity android:name=".Activity.RouteListActivity"
    android:screenOrientation="portrait">
        <intent-filter
            android:autoVerify="true"
            tools:targetApi="23">
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:host="mywebsite.com" android:scheme="http"/>
        <data android:host="mywebsite.com" android:scheme="https"/>
        <data
            android:host="myapp.app.goo.gl/"
            android:scheme="https" />
    </intent-filter>
</activity>

And don't forget to add xmlns:tools="http://schemas.android.com/tools" in the beginning of the manifest.

like image 60
JorgeAmVF Avatar answered Oct 15 '22 09:10

JorgeAmVF