How to handle dynamic links to open a specific content in firestore or realtime database

Viewed 190

My Firestore document contains some text and a photo URL find details of user who added this post in a similar way of social media post.

Now if user clicks on share button in my Android app it will create a dynamic link. Any other user clicks on that link it should open the same firestore document Like insurance all media apps.

In the developers page I don't found how to create deep links for firestore documents or for realtime database content. Also how to handle that data in my app.

Any suggestions will be greatly appreciated. Thanks in advance...

1 Answers

What the dynamic link does when it opens your app is on to you. You can use this listener to handle the event when your app is opened by a dynamic link:

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();
                }


                // Handle the deep link. For example, open the linked
                // content, or apply promotional credit to the user's
                // account.
                // ...

                // ...
            }
        })
        .addOnFailureListener(this, new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "getDynamicLink:onFailure", e);
            }
        });

You can read more about it here. There are a little bit more settings required than only the code itself to make it work.

Related