How an app open custom action after install

Viewed 162

Suppose an user wants to download a music from example.com. User goes to example.com from browser and clicks "download sample.mp3".Now instead of downloading the sample.mp3,the browser downloads an android app. When the user installs the app, the app downloads exactly the same 'sample.mp3' that the user clicked from the browser.

So, how do i make an app like this? Note: i can use download Api to download a music inside onCreate of the app without any views or anything. But the key challenge here is to get the data that the user clicked in the browser (when my app was not even installed). Is it do-able somehow?

1 Answers

You can use firebase dynamic links for that.

You can pass the songId with the link and google play will pass that link into the app after installation. There you can extract the songId and start downloading the song.

One more advantage of the dynamic link is that google play will check if your app is already installed or not. If it is already installed then it will open the app directly else it will redirect to playstore page of the app.

To extract the songId in the app you can use below code:

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