javaandroiddeep-linkingfirebase-dynamic-linksandroid-deep-link

How to get Dynamic Url from firebase


enter image description hereWe are not access share url from firebase using "https://firebase.google.com/docs/dynamic-links/android/receive"

FirebaseDynamicLinks.getInstance()
        .getDynamicLink(getIntent())
        .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
            @Override
            public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                // Get deep link from result (may be null if no link is found)
                Uri deepLink = null;
                if (pendingDynamicLinkData != null) {
                    deepLink = pendingDynamicLinkData.getLink();

                    Log.e("deepLink",""+deepLink.toString());
                }


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

                // ...
            }
        })
        .addOnFailureListener(this, new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "getDynamicLink:onFailure", e);
            }
        });

this method of firebase is allways return null in "onSuccess".


Solution

  • first you need to make sure you URI is formulated like

    https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link]

    method getDynamicLink returns null if a dynamic link is not previously captured or is in the Uri, the above link format is not necessarily to be like that but it should match to the intent filters you have previously defined.

    AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme" >
    
            <activity android:name=".EntryChoiceActivity"
                android:exported="true">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
            <activity android:name=".java.MainActivity"
                android:exported="true">
                <!-- [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="link"
                        android:scheme="your_subdomain.page.link"/>
                </intent-filter> 
            </activity>
        </application>
    
    </manifest>
    

    also you should add query parameters to the link field in the firebase console, https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link] and deep link remain short https://your_subdomain.page.link/example now to reproduce an adb test for a intent filters like:

    <activity
        android:name=".ui.activities.MyActivity"
        android:label="@string/title_activity"
        android:screenOrientation="portrait">
        <!-- ATTENTION: This intent was auto-generated. Follow instructions at
        https://g.co/AppIndexing/AndroidStudio to publish your Android app deep links. -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
    
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- ATTENTION: This data URL was auto-generated. We recommend that you use the HTTP scheme.
            TODO: Change the host or pathPrefix as necessary. -->
            <data
                android:host="link"
                android:scheme="your_subdomain.page.link" />
        </intent-filter>
    </activity>
    

    use:

    adb shell am start -W -a android.intent.action.VIEW -d "your_subdomain.page.link://link?key=category_parent_id\&value=92\&title=test" com.app_name.android

    Hope this help thanks.