Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android firebase dynamic link PendingDynamicLinkData is null direct through app

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>
like image 269
Kim Young Hak Avatar asked Nov 15 '18 07:11

Kim Young Hak


2 Answers

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 .....
                }
            }
        });
    }
like image 173
Onix Avatar answered Oct 20 '22 11:10

Onix


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();
}
like image 36
Umer Softwares Avatar answered Oct 20 '22 11:10

Umer Softwares