Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase dynamic link not opening/launching my installed app [duplicate]

I have developed an android app locally on my device (app not yet on android play store). I have the following logic to get deep link in MainActivity.

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, null)
            .addApi(AppInvite.API)
            .build();

    // Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
    // would automatically launch the deep link if one is found.
    boolean autoLaunchDeepLink = false;
    AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
            .setResultCallback(
                    new ResultCallback<AppInviteInvitationResult>() {
                        @Override
                        public void onResult(@NonNull AppInviteInvitationResult result) {
                            if (result.getStatus().isSuccess()) {
                                // Extract deep link from Intent
                                Intent intent = result.getInvitationIntent();
                                String deepLink = AppInviteReferral.getDeepLink(intent);

                                Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
                                // Handle the deep link. For example, open the linked
                                // content, or apply promotional credit to the user's
                                // account.

                                // ...
                            } else {
                                Log.d(TAG, "getInvitation: no deep link found.");
                            }
                        }
                    });

I built some dynamic links using Firebase console and open in mobile browser. But it is not opening my app and reaching to line String deepLink = AppInviteReferral.getDeepLink(intent);

Instead it is opening the URL in mobile browser itself.

How to open the app and handle deep link in activity while using firebase dynamic link??

Edit:

I have intent filter in the manifest file.

<activity android:name="MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:host="example.com" android:scheme="http"/>
            <data android:host="example.com" android:scheme="https"/>
        </intent-filter>
    </activity>
like image 437
user3559471 Avatar asked Jun 03 '16 09:06

user3559471


People also ask

Do Firebase dynamic links expire?

Method Detail The created short Dynamic Link will not expire. Repeated calls with the same long Dynamic Link or Dynamic Link information will produce the same short Dynamic Link. The Dynamic Link domain in the request must be owned by requester's Firebase project.

How do you debug a Firebase dynamic link?

To help you debug your Dynamic Links, you can preview your Dynamic Links' behavior on different platforms and configurations with an automatically-generated flowchart. Generate the flowchart by adding the d=1 parameter to any short or long Dynamic Link. For example, example. page.

How do I get Firebase dynamic link?

To receive the Firebase Dynamic Links that you created, you must include the Dynamic Links SDK in your app and call the FirebaseDynamicLinks. getDynamicLink() method when your app loads to get the data passed in the Dynamic Link.


5 Answers

Update January 2019

Ensure that you have added the SHA256 certificate fingerprint for your app into your project in the Firebase console.

Add the below code in the AndroidManifest.xml under the activity which you want the dynamic link to lunch:

    <intent-filter android:autoVerify="true">
       <action android:name="android.intent.action.VIEW"/>
       <category android:name="android.intent.category.DEFAULT"/>
       <category android:name="android.intent.category.BROWSABLE"/>
       <data android:host="mydomainname.page.link" android:scheme="http"/>
       <data android:host="mydomainname.page.link" android:scheme="https"/>
   </intent-filter>
  • Remove android:autoVerify="true" if you have Android 6.0 (API level 23) and below or the app will crash.
like image 177
Leo S Avatar answered Nov 07 '22 19:11

Leo S


Alternatively, you could also provide the data in your intent-filter, like stated in the "regular" deep links doc (https://developer.android.com/training/app-indexing/deep-linking.html)

The intent filter would then look like the following :

        <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="https://XXYYZZ42.app.goo.gl/"  // <- Replace with your deep link from the console
                android:scheme="https"/>
        </intent-filter>

That said link can be obtained in your console, right here : enter image description here

EDIT : Added the picture to show where to find this link

like image 21
NSimon Avatar answered Nov 07 '22 20:11

NSimon


Action View and Action Main both are of different Intent category. So, you need to put them in different blocks like this:

 <activity android:name=".DynamicLinkActivity">
        <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="example.com"
                android:scheme="http" />
            <data
                android:host="example.com"
                android:scheme="https" />
        </intent-filter>
    </activity>
like image 21
Raja chakraborty Avatar answered Nov 07 '22 20:11

Raja chakraborty


As explained in another answer, your intent filter seems to have some problems. Also your url may have some problems. When I was playing with those, I had created faulty URL to FireBase web site without noticing it. It is possible to test you code by opening the whole url in your app. I wrote all urls to be tested to an email and sent to myself, open in the device and started clicking. After that you can create the url you want in FireBase. Below are few examples (typos and other errors possible):

If you clicked this url on your device:

https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp

and had this in you manifest:

 <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:scheme="https"
            android:host="mysite.fi"
            android:pathPattern=".*" />
    </intent-filter>

It should open https://mysite.fi/112972 in your app (com.mydomain.myapp) and if you opened the link on your PC, it would open https://mysite.fi/112972 in the browser.

If you opened this url in your device:

https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp&al=myscheme://mydeeplink/112972&afl=http://fallback.fi

and had this in you manifest:

 <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:scheme="myscheme"
            android:host="mydeeplink"
            android:pathPattern=".*" />
    </intent-filter>

It would open myscheme://mydeeplink/112972 in your app (com.mydomain.myapp). You would need to have code for handling it. If the app is not installed, it would open http://fallback.fi in your browser. On the PC it would still open https://mysite.fi/112972.

(edit 19.3.2018) It seems that Firebase does not fully support 'al=' anymore. The code works, but it is missing from the documentation and Firebase console generated urls.

like image 33
diidu Avatar answered Nov 07 '22 21:11

diidu


I had the same problem with deep links not working and the former answers wasn't helping. What did the trick was splitting the "data" tag like this:

Instead of:

<data android:host="example.com" android:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>

Do this:

<data android:host="example.com"/>
<data android:scheme="http"/>
<data android:scheme="https"/>

Hope that will help anyone else :)

like image 22
Shirane85 Avatar answered Nov 07 '22 21:11

Shirane85