我正在开发我的应用中的邀请功能,我希望用户可以推荐给其他人,推荐人在被推荐人注册后会获得奖励。我正在参照Firebase邀请教程,在第二步中,我们通过使用参数invitedby=SENDER_UID
从普通链接创建了一个动态链接。
String link = "https://samplelink.com/?invitedby=" + user.getPhone();
Log.e(TAG, "Generated link: "+link);
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDynamicLinkDomain(getString(R.string.dynamic_link_domain))
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder(getPackageName())
.build())
.setIosParameters(
new DynamicLink.IosParameters.Builder("com.example.ios")
//.setAppStoreId("123456789")
// .setMinimumVersion("1.0.1")
.build())
.buildShortDynamicLink()
.addOnSuccessListener(shortDynamicLink -> {
Uri mInvitationUrl = shortDynamicLink.getShortLink();
Log.e(TAG, "generated URL: "+mInvitationUrl.toString());
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invite_and_earn))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(mInvitationUrl)
// .setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
// .setCallToActionText(user.getPhone())
.build();
startActivityForResult(intent, REQUEST_INVITE);
}).addOnFailureListener(e -> Log.e(TAG, "Error Generating Deeplink: "+e.getLocalizedMessage()));
});
并发送生成的短动态链接
。当用户在步骤4中打开应用程序时,我们获得了类似于该链接的链接。
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
//
// If the user isn't signed in and the pending Dynamic Link is
// an invitation, sign in the user anonymously, and record the
// referrer's UID.
//
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user == null
&& deepLink != null
&& deepLink.getBooleanQueryParameter("invitedby")) {
String referrerUid = deepLink.getQueryParameter("invitedby");
createAnonymousAccountWithReferrerInfo(referrerUid);
}
}
});
链接生成的
短动态链接
很好,发送后,在浏览器中打开时显示原始链接https://samplelink.com/?invitedby=" + user.getPhone()
,但在应用程序中,我只得到了shortdynamiclink
,因此invitedby从未被找到过。有人遇到过这个问题吗?我的短动态链接示例。