39

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.

Arutha
  • 26,088
  • 26
  • 67
  • 80

4 Answers4

32

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.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • 5
    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. – Christopher Orr Feb 24 '10 at 19:57
  • 34
    And, the Web server should have the APK MIME type set up: application/vnd.android.package-archive – CommonsWare Feb 24 '10 at 21:05
  • @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. – trejder May 30 '13 at 14:50
  • @trejder: That behavior may vary by OS level, and perhaps even device. – CommonsWare May 30 '13 at 15:06
  • @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. – trejder Jun 03 '13 at 07:50
  • @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. – bzlm Nov 19 '15 at 09:17
23

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.

Richard C
  • 521
  • 5
  • 5
4

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

Greg
  • 763
  • 6
  • 8
2

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());
    }
}
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
dean
  • 21
  • 1