10

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?

Hammad Nasir
  • 2,889
  • 7
  • 52
  • 133
  • How is the deep link "shared"? Is it so that the friends only receive http://domainname.com/... and click that, or do they receive complete deepnlink, starting with https://myappcode.app.goo.gl/...? Based on how I interpret your question, only http://domainname.com/... is shared and that is definitely wrong if you want to share deep link. – diidu Feb 13 '17 at 10:16
  • I share the whole `deepLink` and friends receives only this much: `http://domainname.com/-KcldzAeJHrPS5tnfxTk?query1=query1&query2=query2&query3=query3` which opens my app on play store then if I go back and open my app manually, the link is received by the app. – Hammad Nasir Feb 13 '17 at 10:27
  • I don't understand how your friends can receive only part of the url if you share it completely. And I don't understand how clicking an url beginning with http://domainname.com/ could open play store. Can you please clarify your question by adding step by step what is happening at which phase and all the details of what data is available in various steps. – diidu Feb 13 '17 at 11:16
  • try adding a static link in the firebase dashboard and see if that works normally. – Youtoo Mar 30 '17 at 15:28

1 Answers1

2

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.

diidu
  • 2,823
  • 17
  • 32
  • what if my app is not published yet and what do you mean by Android link here? – Hammad Nasir Feb 13 '17 at 16:25
  • Your app does not need to be published for you to create it on the firebase console. I assume you have done that if you have "myappcode" for "myappcode".app.goo.gl. I added some references on android link (al) to my reply. – diidu Feb 14 '17 at 13:36
  • @diidu, I see the similar issue, as you explained first point about the way you are opening the link: If I click on link then it always redirects to playstore (when app is not in recent) and PendingDynamicLink is not received after opening the application from playstore. but when I type that in browser it opens the app. Any thoughts, why I am seeing this strange behavior. – SAR Feb 14 '20 at 06:44