How To Show My App In Chooser Apps When Someone Clicks Firebase Dynamic Link?
How should be my android manifest file if I want to show my app in the chooser apps if someone clicks the dynamic link? The URL prefix is like - https://testapp.page.link. At that
Solution 1:
We need to write intent-filter in the manifest file as follows-
<intent-filter><actionandroid:name="android.intent.action.VIEW" /><categoryandroid:name="android.intent.category.DEFAULT" /><categoryandroid:name="android.intent.category.BROWSABLE" /><dataandroid:host="testapp.com"android:pathPattern=".*"android:scheme="https" /><dataandroid:host="testapp.page.link"android:scheme="https"android:pathPattern=".*"/></intent-filter>
Where "testapp.page.link" is the actually the URL prefixes shown at the top left corner of Firebase dynamic link console. And "testapp.com" is the first part of any link. Eg: https://testapp.com/user_profile?id="Zsdsdjwenncsdmsd". From this link, we can extract the user Id as "Zsdsdjwenncsdmsd" at the receiving end of the dynamic link. A complete example is shown below-
If anyone clicks share button this will create the dynamic link-
shareBtn.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
shareProgressBar.setVisibility(View.VISIBLE);
Task<ShortDynamicLink> shortDynamicLinkTask = buildDeepLink(getString(R.string.grp_post_link)+postsModel.getPostId()+"&groupKey="+postsModel.getGroupKey()+"&groupName="+ dataSnapshot.getValue(String.class));
shortDynamicLinkTask.addOnCompleteListener(newOnCompleteListener<ShortDynamicLink>() {
@OverridepublicvoidonComplete(@NonNull Task<ShortDynamicLink> task) {
grpPostsViewHolder.shareProgressBar.setVisibility(View.GONE);
if(task.isSuccessful()){
Uri uri = task.getResult().getShortLink();
share(dataSnapshot.getValue(String.class), uri.toString());
}else {
Toast.makeText(context, "Can't create link", Toast.LENGTH_SHORT).show();
}
}
});
shortDynamicLinkTask.addOnFailureListener(newOnFailureListener() {
@OverridepublicvoidonFailure(@NonNull Exception e) {
shareProgressBar.setVisibility(View.GONE);
}
});
The dynamic link creator function and share function-
/*-----------------------------------------------------------------------------*/privateTask<ShortDynamicLink> buildDeepLink(String deepLink) {
String uriPrefix = getString(R.string.dynamic_links_uri_prefix);
returnFirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(deepLink))
.setDomainUriPrefix(uriPrefix)
.setNavigationInfoParameters(newDynamicLink.NavigationInfoParameters.Builder()
.build())
.setAndroidParameters(newDynamicLink.AndroidParameters.Builder()
.setMinimumVersion(3)
.build())
.buildShortDynamicLink();
}
/*-----------------------------------------------------------------------------*/privatevoidshare(String name, String deepLink) {
String message = "Find "+name+" on SelfieLe - link: "+deepLink;
Intent intent = newIntent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
}
/*---------------------------------------------------------------------------------*/
The String resources are-
R.string.grp_post_link, and R.string.dynamic_links_uri_prefix:
<string name="user_profile_link">https://testapp.com/user_profile?id=</string>
<string name="dynamic_links_uri_prefix">https://testapp.page.link</string>
At receiving end we can extract postId, groupKey etc as follows
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, newOnSuccessListener<PendingDynamicLinkData>() {
@OverridepublicvoidonSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
if (deepLink != null) {
getGrpPost(deepLink.getQueryParameter("id"), deepLink.getQueryParameter("groupKey"), deepLink.getQueryParameter("groupName"));
}else {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(this, newOnFailureListener() {
@OverridepublicvoidonFailure(@NonNull Exception e) {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
});
The getGroupPost(); is as follows
privatevoidgetGrpPost(String id, String groupKey, final String groupName) {
//Do what you want
}
Post a Comment for "How To Show My App In Chooser Apps When Someone Clicks Firebase Dynamic Link?"