我无法使用 Android Firebase Invite SDK 创建 ShortDynamicLink。我可以很好地创建长动态链接,但它总是无法创建短动态链接,总是给出错误请求的错误消息。这是代码:
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 动态链接 API 在 Google 控制台上启用,如下面的屏幕截图所示:
我可以从控制台创建一个简短的动态链接,但我希望能够从客户端以编程方式创建它。我使用的是最新版本的 Android SDK 版本 11.22.1