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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With