带参数的Firebase动态链接 [英] Firebase Dynamic Link with parameters
问题描述
我是社区的新手,由于需要强调我无法解决的问题,所以我加入了.预先感谢您为我提供的任何帮助.
I am new to the community and I have joined because of the need to highlight a problem that I have not been able to solve. Thank you in advance for any answer you can give me to help me.
我目前正在android studio中开发一个项目,并且正在用作firebase数据库,因此需要共享应用程序中的产品,帖子或列表.因此,我决定使用Firebase动态链接来共享某些特定对象.
I am currently developing a project in android studio and I am using as a firebase database, I have come to have the need to share a product, post or list that is within my application. Because of this I have decided to use Firebase Dynamic Link to share some specific object.
我当前的代码试图创建一个链接并共享它,我想知道自己在做错什么,因为它创建了链接并让我共享它,但是没有得到我要传递的参数.在我的情况下,"Lid"是我要通过链接传递的参数,单击链接时,只需选择存储"Lid"的部分即可.
My current code tries to create a link and share it, I would like to know what I am doing wrong, since it creates the link and lets me share it, but it is not getting the parameter that I am passing. In my case "Lid" is the parameter that I want to pass through the link and when clicking on the link, just take the part where the "Lid" is stored.
holder.BtnShare.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
generateDeepLinkUrl(postCurrent.getLid());
String url="https://palsuper.page.link/lista_compartida";
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink( Uri.parse(url))
.setDomainUriPrefix("https://palsuper.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder("com.ibrahim.palsuper")
.setMinimumVersion(1)
.build())
.buildShortDynamicLink( ShortDynamicLink.Suffix.SHORT).addOnCompleteListener( new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
Uri shortURL = task.getResult().getShortLink();
shareDeepLink(shortURL.toString());
} else {
Toast.makeText(mContext, "error", Toast.LENGTH_SHORT).show();
}
}
});
shareDeepLink( url );
}
} );
}
private String generateDeepLinkUrl(String Lid) {
return "https://palsuper.com/lista_compartida=" + Lid ;
}
private void shareDeepLink(String url) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hey! check this content out " + url);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Check this out !");
mContext.startActivity(Intent.createChooser(shareIntent, "Share this cool content"));
}
GetLink.
private void getDynamicLink() {
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();
Toast.makeText(HomeActivity.this, "Link obtenido del intent " + deepLink, Toast.LENGTH_SHORT).show();
// Log.d(TAG, "Link obtenido del intent " + deepLink.getPath());
getAndParseSharedData(deepLink.getPath());
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Log.w(TAG, "getDynamicLink:onFailure", e);
}
});
}
private void getAndParseSharedData(String url) {
String pushKey = "";
if (url.contains("_")) {
String[] parts = url.split("=");
pushKey = parts[1];
// Log.d(TAG, "getAndParseSharedData: " + pushKey);
Toast.makeText(HomeActivity.this, pushKey, Toast.LENGTH_SHORT).show();
}
}
}
推荐答案
Joe您需要将要获取的参数作为查询参数进行传递.
Joe you need to pass the parameter you want to fetch as a query parameter.
Like this:
"https://palsuper.com?lista_compartida=" + Lid;
or
"https://palsuper.com/lista_compartida?lista_compartida=" + Lid;
And then you can fetch it simply using this firebase provided method:
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
String lista_compartida = deepLink.getQueryParameter("lista_compartida");
}
希望这个答案有帮助.
这篇关于带参数的Firebase动态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!