Firebase Dynamic Link ShortUrl not working in Android
I am unable to create a ShortDynamicLink using the Android Firebase Invite SDK. I can create a long DynamicLink, but it fails to create a ShortDynamic link, always giving a Bad Request error. Here is the code:
private void sendInvite(String uid, final String displayName){
String link = "https://appdomain.com/?invitedby=" + uid;
com.google.android.gms.tasks.Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDynamicLinkDomain(Constants.DYNAMIC_LINK_DOMAIN)
.buildShortDynamicLink()
.addOnCompleteListener(mActivity, new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull com.google.android.gms.tasks.Task<ShortDynamicLink> task) {
if (task.isSuccessful()){
Uri shortLink = task.getResult().getShortLink();
// String referrerName = SettingsHelper.getHelper(mActivity).getDisplayName();
String subject = String.format("%s wants you to try Awesome App!", displayName);
String invitationLink = shortLink.toString();
String msg = "Enjoy and share your moments with Awesome App! Use my referrer link: "
+ invitationLink;
String msgHtml = String.format("<p>Start having fun with Awesome App's! Use my "
+ "<a href=\"%s\">referrer link</a>!</p>", invitationLink);
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, msg);
intent.putExtra(Intent.EXTRA_HTML_TEXT, msgHtml);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}else {
String errorMessage = task.getException().getMessage();
Log.d(TAG, "Error creating Dynamic link " + errorMessage);
}
}
});
}
Firebase Dynamic link API is included in Google Console as shown in the screenshot below:
I can create a short dynamic link from the console, but I would like to create it programmatically with client.I am using the current mos version for Android SDK version 11.22.1
source to share
A couple of ideas to test:
1) Make sure Constants.DYNAMIC_LINK_DOMAIN matches the domain in your Firebase project. Make sure the app you created is part of a Firebase project. Make sure the app has an updated GoogleServices.plist (or json).
2) Please share your long link that you are having trouble with to shorten. For a long link, add & d = 1 to the end of the link and navigate to that link in your browser. Make sure there are no errors or warnings on this debug page.
Feel free to open a Firebase bug or email yourself to oleksiyi on google.com if that doesn't work.
source to share
I would suggest to create long link first and then sort link, two steps as in the next question Can't create short dynamic link Firebase -> Dynamic link error 7: Forbidden
source to share