1

I have created dynamic links using firebase console. I have a local app (app not yet on google play store) installed on my device.

This is the code in manifest file for handling dynamic links.

 <activity android:name=".MainActivity" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </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="<code>.app.goo.gl/"
            android:scheme="https"
            android:pathPattern=".*" />

    </intent-filter>
    <!-- [END link_intent_filter] -->
</activity>

This is intent handler in activity

// [START build_api_client]
    // Build GoogleApiClient with AppInvite API for receiving deep links
    GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(AppInvite.API)
            .build();
    // [END build_api_client]

    // [START get_deep_link]
    // 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);

                                // Handle the deep link. For example, open the linked
                                // content, or apply promotional credit to the user's
                                // account.

                                // [START_EXCLUDE]
                                // Display deep link in the UI
                                //((TextView) findViewById(R.id.link_view_receive)).setText(deepLink);
                                Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
                                // [END_EXCLUDE]
                            } else {
                                Log.d(TAG, "getInvitation: no deep link found.");
                            }
                        }
                    });
    // [END get_deep_link]

when i open dynamic link in mobile browser, it is not redirecting me to app. instead opening the link in mobile browser itself.

How to open the app when user try to hit dynamic link in mobile browser?

user3559471
  • 563
  • 2
  • 6
  • 17
  • I think what you need is an [Intent Handler](https://developer.android.com/training/app-links/index.html#intent-handler) – AL. Jun 06 '16 at 08:59
  • That is already there. Updated the question with handler. – user3559471 Jun 06 '16 at 09:01
  • Sorry. I didn't notice.. Is there any error that shows up? Or any logs that can confirm if it actually goes through your code? – AL. Jun 06 '16 at 09:06
  • 1
    Its not showing any error or logs. I think it is not going through my code. – user3559471 Jun 06 '16 at 09:14
  • How does your url look like? I think your host (in the manifest) should be something else than the URL created by firebase. Of course it can be anything as long as you write handler for it, but that seems peculiar. Your host should be either from the "link" or "al" of the url you clicked. – diidu Jun 06 '16 at 09:38
  • @diidu Thanks for response. But i didn't understand your point. currently my url look like https://.app.goo.gl/VMUp. This is the same url created by firebase. please let me know if i m missing anything. – user3559471 Jun 06 '16 at 10:13
  • @user3559471 that is the short url, how does it look like when opened? What are the parameters you gave when creating it (especially "link" and "al", if given). The opened url would look something like: https://.app.goo.gl/?link=https://www.example.com/someresource&apn=com.example.android&amv=3&ad=1 depending on what parameters you gave (as explained here https://firebase.google.com/docs/dynamic-links/android#create-a-dynamic-link-programmatically) – diidu Jun 06 '16 at 10:47
  • @diidu For testing i havn't provided any params except link. Currently it looks like this. https://.app.goo.gl/?link=google.com – user3559471 Jun 06 '16 at 11:18
  • @diidu i tried with new dynamic link also. which look like this. https://.app.goo.gl/?link=google.com&apn= But that also doesn't work. – user3559471 Jun 06 '16 at 11:27
  • 1
    @user3559471 how are you creating link? – Faris Jameel Jul 12 '16 at 12:18
  • Here's the interesting part. You don't need to write any code for the Dynamic Link to just open the app. The magic happens in creating the link correctly - 1) make sure that the "link flow" chosen from the link menu is set up correctly, 2) make sure the package name of your app is correct, 3) make sure the SHA256 key is configured correctly. If Google Play is on your device, it will intercept the URL, and try to launch the specified app. To summarise: there is nothing wrong with the manifest. – Richard Le Mesurier Apr 06 '17 at 12:54
  • Possible duplicate of [Firebase dynamic link not opening the app](http://stackoverflow.com/questions/37610950/firebase-dynamic-link-not-opening-the-app) – Richard Le Mesurier Apr 06 '17 at 12:58

1 Answers1

1

There are some problems with both your url and your manifest. The "link" parameter needs to contain also the scheme, so with minimum changes it should be:

https://<code>.app.goo.gl/?link=https://google.com&apn=<package name>

(note the added https://) and when using that link your manifest should look like:

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

You can test your app with the full url before creating the short url on the firebase web page. This helps you ensure you get the app right before creating the short url for real use.

When using http/https schemes, android should first ask whether you want to open browser or your app. I prefer using "al" with app specific scheme to opening a view on my app.

diidu
  • 2,823
  • 17
  • 32
  • I tried with changes suggested by you. Both long and short url opening google page in laptop browser as well as in mobile browser. This is long url look like: https://.app.goo.gl/?link=https://google.com&apn= – user3559471 Jun 06 '16 at 11:51
  • 1
    Laptop browser works as expected. How do you test the url? Try clicking the url (eg. on web page or on an email email) rather than writing it on the browser address window. I assume your is exactly the same as your app package name, as it should be. – diidu Jun 06 '16 at 12:02
  • I tried with clicking on link (send via sms). rechecked package name, it is correct. is that possible, the problem is happening because my app in not on play store? Just to inform, i have installed the app locally (not with play store) – user3559471 Jun 06 '16 at 12:10
  • I don't think the app needs to be in play store for this to work. My app is there, but when the app is already installed on the device, I don't think play store is involved. (if I have no app installed, the link will open correct play store page, but during development I am naturally working with locally installed app). No 100% knowledge on this though. I recommend you try giving "al=myscheme://myhost" next, you need to set those in your manifest and implement handling for those in your code. But then you are fully flexible to do anything. – diidu Jun 06 '16 at 12:48
  • Also you should ensure that the browser is not set as default handler for https://google.com (Application Management->your app->Start as default) – diidu Jun 06 '16 at 12:50