Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Deep-link opening play store even when the app is installed

I'm developing an android app.

Upon clicking a button, a deep-link is generated and shared with friends.

The problem is that upon clicking that shared deep-link, play store is getting opened even when the app is installed.

I followed this documentation.

Here's the intent-filter:

            <!-- [START link_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>
            <!-- [END link_intent_filter] -->

Here's how I'm creating the url (manually):

        Uri BASE_URI = Uri.parse("https://domainname.com/");
        packageName = getBaseContext().getPackageName();
        APP_URI = BASE_URI.buildUpon().path(requestID.getText().toString().trim())
             .appendQueryParameter("query1", query1.getText().toString())
             .appendQueryParameter("query2", query2.getText().toString())
             .appendQueryParameter("query3", query3.getText().toString()).build();

        try {
           String encodedUri = URLEncoder.encode(APP_URI.toString(), "UTF-8");
           deepLink = Uri.parse("https://myappcode.app.goo.gl/?link="+encodedUri+"&apn="+holder.packageName+"&amv="+16+"&ad="+0);
        } catch (UnsupportedEncodingException e) {
           e.printStackTrace();
        }

Here's the received deep-link/url: http://domainname.com/-KcldzAeJHrPS5tnfxTk?query1=query1&query2=query2&query3=query3

What could be wrong here?

like image 211
Hammad Nasir Avatar asked Jul 02 '16 06:07

Hammad Nasir


People also ask

What happens with a deep link if the app is not installed?

If the app is installed, the user will be taken to the app via the deep link. If and only if the app is not installed, the click will not go anywhere. Therefore, bidders should only create deep links for users that they know have previously installed the app, based on data from their analytics SDK(s).

What is difference between deep link and dynamic link?

Dynamic Links are deep links into an app that work whether or not users have installed the app yet. When users open a Dynamic Link into an app that is not installed, the app's Play Store page opens, where users can install the app. After users install and open the app, the app displays the deep-linked content.

How do I enable dynamic links in Firebase?

You create a Dynamic Link either by using the Firebase console, using a REST API, iOS or Android Builder API, or by forming a URL by adding Dynamic Link parameters to a domain specific to your app. These parameters specify the links you want to open, depending on the user's platform and whether your app is installed.

How do Firebase deep links work?

Deep links that survive the install processDynamic Links are smart URLs that allow you to send existing and potential users to any location within your iOS or Android app. They survive the app install process, so even new users see the content they're looking for when they open the app for the first time.


1 Answers

There are at least three things that could possibly be wrong:

The way you are opening the url: I saw similar problem when writing the url to browser window on Android device. When adding the link to an email and clicking it, the app was opened. You write "click" so perhaps this is not the problem.

Your url and your app/manifest do not match: You have not added proper intent handler for the protocol or the host to correct place in your manifest or your url does not match with what you have added. Or apn given in the url does not match your apps package name. Based on the question in the current state the host does not match.

You are not sharing the deeplink url, but just an ordinary url: If you expect the shared url to open preinstalled app, your friends will need to click (on an email or similar) the complete deeplink url, which then either directs the link to play store (if app is not installed) or opens the app (if correctly implemented). Normal url is just opened in the browser. Based on the current state of the question, this could be the case.

If fixing the above does not work: Try adding specific Android link to your url, something like this:

https://<myappcode>.app.goo.gl/?link=http://domainname.com&apn=com.doman.app&amv=16&ad=0&al=myscheme://any-string-you-choose

after which your intent filter should be something like this:

     <!-- [START link_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="any-string-you-choose" android:scheme="myscheme"/>
        </intent-filter>
        <!-- [END link_intent_filter] -->

I prefer this way since it is a bit more flexible compared to using only link. Naturally the package name and other things need to be correct also when using this method. Android link is url to be opened only in android app, a bit poorly documented, check it from here (the example). Also my reply to another question gives some examples on how to use it.

(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 169
diidu Avatar answered Sep 21 '22 16:09

diidu