apk installation from web page

64,245

Solution 1

Just link to the apk file in the HTML. It couldn't be any simpler.

<a href="path to my .apk file">link</a>

You will have to have "install apps from unknown sources" enabled on your phone.

Solution 2

If you're using ASP.NET, then you'll need to insert the following in your web.config file:

<configuration>
  ...

   <system.webServer>
      <staticContent>
         <mimeMap fileExtension=".apk"
                  mimeType="application/vnd.android.package-archive" />
      </staticContent>
   </system.webServer>

  ...
</configuration>

Apart from that (as others have said), you just need a normal link:

<a href="myAndroidApp.apk">Click here</a>

and tell your users to enable the Security -> Unknown sources option in Settings.

Solution 3

Extra help for IIS webservers: mbaird's example worked great for me after I added the apk mime type to my IIS webserver. I just put an html file up with that link, but got a 404 error when trying to pull up my test.apk file without the .apk mime entry. As Commonsware said, make sure to allow .apk files in the mime types - this is for sure still necessary on an IIS webserver. You can do this from IIS Manager, select the server, and find "Mime Types", then add an entry. Example of adding a Mime entry for the apk file in IIS

Solution 4

In .Net this is what I did, I created an .asmx page then a QR code that pointed to it other wise I kept getting a 404, then this on page load.

protected void Page_Load(object sender, EventArgs e){
    ViewState["PreviousPage"] = Request.UrlReferrer;
    string filepath = Server.MapPath("AcsMainMenu.apk");
    FileInfo droidfile = new FileInfo(filepath);

    if (droidfile.Exists)
    {
        Response.ClearContent();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + droidfile.Name);
        Response.AddHeader("Content-Length", droidfile.Length.ToString());
        Response.ContentType = "application/vnd.android.package-archive";
        Response.TransmitFile(droidfile.FullName);
        Response.Flush();
        Response.End();
        Response.Redirect(ViewState["PreviousPage"].ToString());
    }
}
Share:
64,245
Arutha
Author by

Arutha

Updated on June 26, 2020

Comments

  • Arutha
    Arutha almost 4 years

    I'm looking for a sample web page (html code) with a link that will install an apk file directly on my phone by clicking on the link.

  • Christopher Orr
    Christopher Orr about 14 years
    However, the install may not start immediately; the user may have to manually click on the APK in their browser's downloads list. Then they'll need to click the "Install" button to approve your app's requested permissions. The short answer is it's not possible with a single click. And if the user doesn't have the "unknown sources" option enabled (it's disabled by default), they'll get a warning message and the install won't happen.
  • CommonsWare
    CommonsWare about 14 years
    And, the Web server should have the APK MIME type set up: application/vnd.android.package-archive
  • Fredrik Stolpe
    Fredrik Stolpe over 11 years
    But wasn't this because you hadn't added the .apk mime type to IIS?
  • Richard C
    Richard C about 11 years
    Much easier than this is to edit the web.config file - see my answer below.
  • trejder
    trejder almost 11 years
    @CommonsWare: This is no longer required. My servers does not set such MIME type and *.apk files are being downloaded without any problems on either mobile or desktop browsers.
  • CommonsWare
    CommonsWare almost 11 years
    @trejder: That behavior may vary by OS level, and perhaps even device.
  • trejder
    trejder almost 11 years
    @CommonsWare: Yes, you're right. I did tests on newest Android (4.2.1) on pure Google (Nexus) device, so I assumed, that if this works without MIME (on server-side) for "pure" set, it should for every one else. But, you're right, that I shouldn't generalize. Thanks.
  • user772401
    user772401 over 8 years
    @trejder Just verified that the content-type in the http response does make a difference (pure legit 4.x). Without the correct content-type, download worked but install didn't. I'm guessing Android doesn't care about the file extension when determining which app to "open" the downloaded file with.
  • user772401
    user772401 over 8 years
    @FredrikStolpe Most likely. Without the mime type defined anywhere (IIS or site or app), IIS would 404.