11

I've exported an apk from eclipse. I am able to install it without any problem if I copy it to the phone's sd card.

When trying to download via phone's (Galaxy S) browser I get: "Download unsuccessful".

I have set mime type application/vnd.android.package-archive in the mime.types, restarted apache, still same result. Also tried :

<a href="downloads/my_apk.apk" type="application/vnd.android.package-archive">Download App</a>

Still no luck.

I am able to download and install applications from android market. I suspect that apache is not sending the mime type but this is just a shot in the dark. How can I fix the problem and be able to install APKs from my web server? (or at least to check if apache sends correct header with mime type)

Any help will be appreciated.

Ognyan
  • 13,452
  • 5
  • 64
  • 82

4 Answers4

19

It is better if you add the .apk extension to the apache`s mime config. Take a look at this example: https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

You can just find the "apk" record and copy the row to the file /etc/mime.types at your server:

application/vnd.android.package-archive     apk

Also add this to /etc/apache2/mods-available/mime.conf :

AddType application/vnd.android.package-archive .apk

(There are some other AddType-s, put it after them for sure). From here on you don't have to put anything for the apk`s mime-type in the tag, the server will handle this. ;)

UPDATE: fixed a bug in AddType line

Raptor
  • 53,206
  • 45
  • 230
  • 366
Vasil Popov
  • 1,210
  • 14
  • 22
  • For Windows Apache installation, the file mime.types is located at {APACHE_INSTALL_PATH}/conf/ , and add the AddType line in httpd.conf near other AddType lines – Raptor Jun 03 '11 at 01:45
  • My server does not have a /etc/apache2/mods-available/mime.conf - and editing /etc/mime.types was sufficient; though I think restarting the apache was needed. – Danny Schoemann Sep 08 '14 at 10:30
10

After all I found the problem thanks in part to CommonsWare advise.

Directory where I put apks for downloads is protected by simpe auth. Phone's browser correctly asks (once) for username/password when browsing it but obviously forgets to send auth info when trying to download the file and that causes 401 Unauthorized.

Solution: remove basic auth from that dir or use another unprotected dir for the apks.

Ognyan
  • 13,452
  • 5
  • 64
  • 82
  • This worked for me. In Apache 2.2 to remove auth from subdir, instead of "AuthType None" (which is not available in 2.2), you can add two lines "Satisfy Any" / "Allow from all" to a Directory directive (or .htaccess file). – jimhark Aug 26 '11 at 20:38
  • This seems insecure, what if you want to still protect your APKs? – Greg Martin Apr 24 '12 at 02:20
  • @greg AFAIK the bug in browser is fixed so there is no need to remove the basic auth – Ognyan Apr 25 '12 at 12:48
  • Which version was it fixed in? – Greg Martin Apr 30 '12 at 21:26
  • In 2.3 it is working fine. In 2.1 you may use different browser as opera in order to circumvent the bug. – Ognyan May 01 '12 at 06:14
  • Hi, I am a newbie to Android developement. I am GETting the .apk file using HttpConnection. When I try to install the .apk from SDCard it is throwing PARSE ERROR. But I am able to install by loading the .apk to SDCard. I am not accessing the link via browser. – varunrao321 May 07 '12 at 06:54
  • 1
    I still had the issue on Android 4.1.2 and removing the basic auth solved it for me. – Patrick Rudolph Oct 23 '12 at 06:45
3

Use curl to test the Web server to make sure it is responding to the HTTP request and returning the proper MIME type. Also, example your server logs to see what error is being logged.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

Sometimes you have no access to apache configuration files like /etc/mime.types, especially on the shared servers. You can create file .htaccess (or open if it already exists) in your root directory and add the following string: AddType application/vnd.android.package-archive .apk Hope it helps.

JEX725
  • 61
  • 5