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>
Kim Young Hak
  • 113
  • 1
  • 6

3 Answers3

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 .....
                }
            }
        });
    }
Onix
  • 662
  • 3
  • 10
  • 1
    onNewIntent is never called – Kim Young Hak Nov 15 '18 at 09:03
  • 1
    try add to AndroidManifest.xml to your tag android:launchMode="singleInstance" – Onix Nov 15 '18 at 09:10
  • Do you use for handle PendingDynamicLinkData MainActivity that has intent-filter category android:name="android.intent.category.LAUNCHER? – Onix Nov 15 '18 at 09:29
  • I am using the same activity to handle dynamic links which has intent-filter category android:name="android.intent.category.LAUNCHER – Umer Nov 04 '19 at 03:33
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();
}
Umer
  • 566
  • 6
  • 13
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.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169