3

Is there any way to signal Android OS to open the package installer upon download of an .apk file?

Perhaps by Content-Type? or maybe an APK specific url protocol, like apk://apk.location?

Henrique Viecili
  • 141
  • 1
  • 10

1 Answers1

1

Are you doing the download yourself in your own app, or are you trying to create some behavior in an external app?

I don't think you'll be able to trigger behavior upon download outside of your app (since the user would have to select the downloaded file in order to open it), but if you're handling the download yourself, I think you want this post on how to install an application programmatically.

Edit: Addressing your comment in which you said you are writing a website and want to be able to force the APK to be opened by a native app: I can think of a way to do something like it, but you would have to handle the download in the native app because you won't get the browser to do the download for you.

You'll need to register your native app to receive ACTION_VIEW Intents with URIs in whatever format you choose; I recommend using something like yourappname://localhost/escaped_download_url_to.apk. In your Activity get the path from the URI in the Intent and grab the last part of it (URI handling is broken into a few components: protocol, host, and path). Unescape it as necessary and then start the download manually in the app, and then upon completion you open the downloaded APK from wherever your app put it, using the link I provided.

So long as you make sure your mobile website provides an href to yourappname://localhost/escaped_download_url_to.apk, you'll be able to trigger this behavior. When the user clicks that link, it should provide a dialog to choose which app to use to open it (if they have more than one app capable of doing so) which when they select your app will launch the Activity that you registered with the Intent filter.

Edit the second: you probably don't need to do any escaped URIs; just using a made-up URI protocol as you suggest in your own post should work, so long as your app registers to receive Intents with that protocol. yourappname://yourserver.com/my/location.apk will work. All that really matters is being able to pull the download URL out of the data you give to the app in the URI.

Community
  • 1
  • 1
Jon O
  • 6,532
  • 1
  • 46
  • 57
  • I saw the post you mentioned. But I'm trying to create a download link to a native app in a mobile website and open/install the file right away. – Henrique Viecili Aug 23 '12 at 13:21