我创建了动态链接,我想发送一些特定的参数,例如:
"https://mydynamiclink/?link= "+ 链接 + "&msgid="+ id + "&apn=myapn"。
link
字段看起来像“https://play.google.com/store/apps/details/?id=com.myApp&msgid=myId&apn=myapn”
当我点击此链接后打开我的应用程序时 - 我收到 PendingDynamicLinkData
并且可以从中获取链接,但不能获取一些自定义数据。 (pendingDynamicLinkData.getLink()
返回没有“&msgid=...”的链接 - 我得到字符串“https://play.google.com/store/apps/details/?id=com.myApp”)
我怎样才能添加我的 msgid 字段并最终获取它?
最佳答案
接受的答案对我来说效果不佳,我需要做的就是检查链接是否针对用户的个人资料而不是博客文章,这样我就可以重定向到我的 ProfileActivity。
private void generateDynamicLink() {
//build link normally and add queries like a normal href link would
String permLink = getLink() + "?route=profile&name=" + getProfileName()
+ "&category=" + getUserPracticeCategory()
+ "&picture=" + getProfilePicture();
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(permLink))
.setDynamicLinkDomain(Constants.DYNAMIC_LINK_DOMAIN)
.setAndroidParameters(new
DynamicLink.AndroidParameters.Builder().build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setTitle("Enter Title")
.setDescription("Enter Desc here")
.setImageUrl(Uri.parse(getProfilePicture()))
.build())
.buildShortDynamicLink()
.addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT,task.getResult().getShortLink());
intent.setType("text/plain");
startActivity(intent);
} else {
Utils.snackBar(tvAddress, "Failed to Generate Profile Link, Try
Again");
}
});
}
当用户使用生成的链接导航到我的应用程序时,它会转到发布详细信息 Activity ,因为我将该 Activity 设置为 list 中唯一可浏览的 Activity 。然后我必须使用路由查询来确定传入链接是博客文章还是共享的用户配置文件。
private void retrieveDynamicLink() {
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent())
.addOnSuccessListener(this, pendingDynamicLinkData -> {
if (pendingDynamicLinkData == null) {
retrieveLocalIntent();
} else {
Toast.makeText(context, "Resolving Link, Please Wait...", Toast.LENGTH_LONG).show();
if (pendingDynamicLinkData.getLink().getQueryParameter("route") != null) {
if (Objects.requireNonNull(pendingDynamicLinkData.getLink().getQueryParameter("route")).equalsIgnoreCase("profile")) {
try {
Uri uri = pendingDynamicLinkData.getLink();
String permLink = uri.toString().split("\\?")[0];
Intent intent = new Intent(this, ProfileActivity.class);
intent.putExtra(ProfileActivity.PROFILE_NAME, uri.getQueryParameter("name"));
intent.putExtra(ProfileActivity.PROFILE_CATEGORY, uri.getQueryParameter("category"));
intent.putExtra(ProfileActivity.PROFILE_PICTURE, uri.getQueryParameter("picture"));
intent.putExtra(Utils.POST_PERMLINK, permLink);
startActivity(intent);
this.finish();
} catch (NullPointerException e) {
Toast.makeText(context, "Unable to View User Profile", Toast.LENGTH_SHORT).show();
}
}
} else {
postHrefLink = pendingDynamicLinkData.getLink().toString();
getPostDetail.getData(postHrefLink);
}
}
})
.addOnFailureListener(this, e ->
retrieveLocalIntent()
);
}
希望这对您有所帮助。
关于android - 将查询参数添加到 firebase 动态链接中的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52943550/