3

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?

because_im_batman
  • 975
  • 10
  • 26
Abdul Alim
  • 110
  • 7
  • It's very unclear what you're asking. Can you explain in a bit detail please? – SaadAAkash Oct 03 '19 at 16:48
  • Suppose, I looking for downloading a song named "Baby.mp3" from example.com But, when I, clicked on the song download button on the download page, it started downloading an android app. And then, I Installed that app on my phone. But, the fact is, when I, open that app for first time it started downloading the song named "Baby.mp3" on the app as like a web browser. – Abdul Alim Oct 03 '19 at 16:57
  • Okay for that you just need to create an app that hits the download API from the `onCreate()` of the first Activity that launches, registered in the manifest xml. – SaadAAkash Oct 03 '19 at 17:03
  • This might be related to install referrer, you can add a GET param (referrer) in the download url of a google play app that will be transmitted to the app on install : https://stackoverflow.com/questions/30103338/android-is-it-possible-to-get-install-referrer-programmatically – Hacketo Oct 03 '19 at 17:04
  • But, how i get the user data, like the file name which he/she tried to download from example.com? – Abdul Alim Oct 03 '19 at 17:05

1 Answers1

3

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);
        }
    });
Ashu Tyagi
  • 1,400
  • 13
  • 25