在调查了这个话题之后,我发现了 Google Firebase 动态链接。我看了一些关于这个话题的视频。此代码生成一个可由链接共享的密钥。首先,您必须在 Firebase 控制台中创建一个动态链接。然后,添加这些方法。这是获取动态链接数据的第一种方法:
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// getting deep link
Uri deeplink = null;
if(pendingDynamicLinkData != null){
deeplink = pendingDynamicLinkData.getLink();
}
// getting deeplink content
if(deeplink != null)
{
String sharedList = deeplink.getQueryParameter("sharedList");
userReference[0] = database.getReference(sharedList);
}
else userReference[0] = database.getReference().push();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, "Ooops, we couldn't get the link data :(", Toast.LENGTH_SHORT).show();
}
});
这是第二个,生成链接:
// generating dynamic link
private void GenerateLink(String listId) {
System.out.println("Generating link: " + listId);
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://www.your_dynamic_link.com/?your_variable_to_share=" + value))
.setDomainUriPrefix("https://your_short_url.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder("com.example.your_package")
.setMinimumVersion(1)
.build())
.buildDynamicLink();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "I share you my list: " + dynamicLink.getUri());
sendIntent.setType("text/plain");
startActivity(sendIntent);
}