user3559471
user3559471

Reputation: 583

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

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?

Upvotes: 1

Views: 6783

Answers (1)

diidu
diidu

Reputation: 2863

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.

Upvotes: 1

Related Questions