1
votes

I'm working with firebase dynamic links on android to generate links programmaticaly when a user shares a specific content .

   Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT,"Subject");
        sendIntent.setType("text/plain");
        FirebaseDynamicLinks.getInstance().createDynamicLink()
                .setLongLink(Uri.parse("https://organization.page.link/?link=https://www.organization.com/content.htm"))
                .setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
                .buildShortDynamicLink()
                .addOnCompleteListener((Activity) context, task -> {
                    if (task.isSuccessful()) {
                        sendIntent.putExtra(Intent.EXTRA_TEXT, task.getResult().getShortLink());
                        context.startActivity(Intent.createChooser(sendIntent, "Share")));
                    }
                });

Everything works fine here, except when the receiver of the dynamic link doesn't have the app installed , so it redirects him to the website instead of Play Store. I have tried .setFallbackUrl() but it doesn't work.

1
Show your generated link - Rutvik Bhatt

1 Answers

0
votes

I have found the problem:

When I use

.setLongLink(Uri.parse("https://organization.page.link/link=https://www.organization.com/content.htm"))

the link is always resolved, then Android opens the URL instead of Play Store . I have replaced that with

.setLink(Uri.parse("www.organization.com/content.htm"))

And adding

.setDynamicLinkDomain("organization.page.link")

Final code

FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLink(Uri.parse("https://organization.com/content.htm"))
.setDynamicLinkDomain("organization.page.link")
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
                        .buildShortDynamicLink()
                        .addOnCompleteListener((Activity) context, task -> {
                            if (task.isSuccessful()) { 
                                   // Get Dynamic link here
                                 }
                        });