Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Dynamic Links working but not showing image Android

I am using Firebase Dynamic Links in my Android app, as previously mentioned, and it is working well. The problem is that when I share it, for example in WhatsApp, the link does not show the image, while it is showing title and description. The type of link used is the short one (using the large one, it works perfectly).

This is my code:

    FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLongLink(buildDynamicLink())
            .buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT)
            .addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
                @Override
                public void onComplete(@NonNull Task<ShortDynamicLink> task) {

                    if (task.isSuccessful()) {
                        //Uri previewLink = task.getResult().getPreviewLink();
                        Uri shortLink = task.getResult().getShortLink();
                        shareApp(shortLink.toString());
                    } else {
                        Toast.makeText(MainActivity.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
            });

buildDynamicLink method:

private Uri buildDynamicLink(){

    String uri =  "https://appname.page.link/" +
            "?link=" + "https://www.appname.com/" +
            "&apn=" + getPackageName() +
            "&ibn=" + "name" +
            "&st=" + "Title" +
            "&sd=" + "Description" +
            "&si=" + "validImageUrl";
    return Uri.parse(uri);

Share Intent

private void shareApp(String uri){
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT,uri);
    intent.setType("text/plain");
    startActivity(intent);
}

Can anyone help me with this issue?

Thank you all in advance.

like image 781
German Avatar asked Feb 03 '19 18:02

German


1 Answers

The documentation says that the image have to be 300X200 at least and less than 300KB. Check it before. Dynamic links documentation

Other way is to use this method to build the long URL:

DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
    .setLink(Uri.parse("https://www.example.com/"))
    .setDomainUriPrefix("https://example.page.link")
    .setAndroidParameters(
            new DynamicLink.AndroidParameters.Builder("com.example.android")
                    .setMinimumVersion(125)
                    .build())
    .setIosParameters(
            new DynamicLink.IosParameters.Builder("com.example.ios")
                    .setAppStoreId("123456789")
                    .setMinimumVersion("1.0.1")
                    .build())
    .setGoogleAnalyticsParameters(
            new DynamicLink.GoogleAnalyticsParameters.Builder()
                    .setSource("orkut")
                    .setMedium("social")
                    .setCampaign("example-promo")
                    .build())
    .setItunesConnectAnalyticsParameters(
            new DynamicLink.ItunesConnectAnalyticsParameters.Builder()
                    .setProviderToken("123456")
                    .setCampaignToken("example-promo")
                    .build())
    .setSocialMetaTagParameters(
            new DynamicLink.SocialMetaTagParameters.Builder()
                    .setTitle("Example of a Dynamic Link")
                    .setDescription("This link works whether the app is installed or not!")
                    .build())
    .buildDynamicLink();  // Or buildShortDynamicLink()

I'm not pretty sure about it because i have just done it with Flutter but the way to add the image you want is on the setSocialMetaTagParameters(). I think you should code it like this:

new DynamicLink.SocialMetaTagParameters.Builder()
                .setTitle("Shared Title")
                .setDescription("Description that you will see on whatsapp")
                .setImageUrl("yoururl.com/image.png")//Your url HERE
                .build()

If you use this method you will get a lorg dynamiclink and to get a short link you can use the buildShortDynamicLink() insted of buildDynamicLink()

Hope this helps you!

like image 72
David Benitez Riba Avatar answered Sep 19 '22 09:09

David Benitez Riba