7

I tried the below firebase official dynamic link sample but is not working for me.

Dynamic Link:

Mainfest:

 <activity android:name=".java.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="plpsoft.page.link"
                    android:scheme="https"/>
                <data
                    android:host="plpsoft.page.link"
                    android:scheme="http"/>
            </intent-filter>
            <!-- [END link_intent_filter] -->
        </activity>

Activity:

@Override
        protected void onCreate(Bundle savedInstanceState) {
      FirebaseDynamicLinks.getInstance()
                    .getDynamicLink(getIntent())
                    .addOnCompleteListener(new OnCompleteListener<PendingDynamicLinkData>() {
                        @Override
                        public void onComplete(@NonNull Task<PendingDynamicLinkData> task) {
                            Uri deepLink = null;
                            if (task.getResult() != null) {
                                deepLink=task.getResult().getLink();
                                ((TextView) findViewById(R.id.linkViewReceive))
                                        .setText(deepLink.toString());

                            }
                        }
                    })
                    .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();
                            }


                            // 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
                            if (deepLink != null) {
                                Snackbar.make(findViewById(android.R.id.content),
                                        "Found deep link!", Snackbar.LENGTH_LONG).show();

                                ((TextView) findViewById(R.id.linkViewReceive))
                                        .setText(deepLink.toString());
                            } else {
                                Log.d(TAG, "getDynamicLink: no link found");
                            }
                            // [END_EXCLUDE]
                        }
                    })
                    .addOnFailureListener(this, new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Log.e("Splash", "getDynamicLink:onFailure", e);
                        }
                    })
                    .addOnFailureListener(this, new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Log.w(TAG, "getDynamicLink:onFailure", e);
                        }
                    });
    }

While tapping the URL the app will launch successfully and i get the intent data URI string also. if i pass this URI to getDynamicLink() method it's return as null. I also add the both SHA1 and SHA256 key in firebase console.

James Z
  • 12,209
  • 10
  • 24
  • 44
PLP
  • 714
  • 3
  • 13
  • Getting same error which we extracting the firebase deep link url in Android app. Any one is experienced the same, please help. – Rajesh M P Apr 29 '20 at 15:22
  • 1
    I was only able to get the link using: Uri link = getIntent().getData() Unsuccessful with: FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()) – user3394003 Apr 06 '21 at 18:48

1 Answers1

0

I was able to fix it by removing the intent-filter from the manifest and adding the callback handler in the MainActivity.

What the docs says is that:

In the callback the PendingDynamicLinkData is returned in addOnSuccessListener(OnSuccessListener) or addOnCompleteListener(Activity, OnCompleteListener) which returns the most recently clicked dynamic link, or null if a dynamic link was not pending as captured data or in the intent.

So the deeplink was being captured by the intent filter and because it was not longer pending the callback returns null

DonGuti
  • 1
  • 1