android firebase dynamic link PendingDynamicLinkData is null direct through app
Asked Answered
S

3

9

Problem: Why is "Short dynamic links" created programatically wont open/launch the app directly?

I want to launch app directly when user clicks the dynamic url created dynamically by android app.

When clicking dynamic short link created dynamically by android app the following things happen,

1.Option show two options one is through chrome other is through app

2.if i choose chrome option, browser opens, shows a loading dialog box and launch app with PendingDynamicLinkData data

3.but if i choose app option, app lauches app but PendingDynamicLinkData is lost or null.

Any Help would be great. my manifest setting is below

  <intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:host="myapp.page.link" android:scheme="http"/>
    <data android:host="myapp.page.link" android:scheme="https"/>
  </intent-filter>
Seed answered 15/11, 2018 at 7:49 Comment(1)
having same issue brother have any solution?Wernher
R
4

You should handle your PendingDynamicLinkData in activity to override onCreate and onNewIntent. Like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        if (intent != null) {
            handleDeepLink(intent);
        }
}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (intent != null) {
        handleDeepLink(intent);
    }
}

private void handleDeepLink(Intent intent) {
        FirebaseDynamicLinks.getInstance().getDynamicLink(intent).addOnSuccessListener(pendingDynamicLinkData -> {
            if (pendingDynamicLinkData != null) {
                Uri deepLink = pendingDynamicLinkData.getLink();
                if (deepLink != null) {
                    // todo .....
                }
            }
        });
    }
Rhinal answered 15/11, 2018 at 8:48 Comment(4)
onNewIntent is never calledSeed
try add to AndroidManifest.xml to your <activity> tag android:launchMode="singleInstance"Rhinal
Do you use for handle PendingDynamicLinkData MainActivity that has intent-filter category android:name="android.intent.category.LAUNCHER?Rhinal
I am using the same activity to handle dynamic links which has intent-filter category android:name="android.intent.category.LAUNCHERDignity
D
1

I don't know the correct solution but I have found a trick that works. First make sure that you have added the following intent filter to the activity that is supposed to handle the dynamic link:

    <intent-filter android:autoVerify="true">
        <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>

Source

Then in your activity, use the following code to get the link:

String link=null;
if (getIntent().getData()!=null){
    link=getIntent().getData().toString();
}
Dignity answered 5/11, 2019 at 16:44 Comment(0)
C
0

In the manifest, add the following intent filter to the activity that will handle the url:

override OnStart method of the target Activity:

public override fun onStart() {
    super.onStart()
    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();
            }
            // ...
        }
    })
    .addOnFailureListener(this, new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w(TAG, "getDynamicLink:onFailure", e);
        }
    });

The complete guide here. For some reason, i couldn't make it work in the same activity that as action MAIN.

Circassian answered 5/1, 2020 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.