Android 无法安装 APK 托管我自己的 apache 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3569313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:47:15  来源:igfitidea点击:

Can't install APK hosted my own apache server

android

提问by Ognyan

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.

我已经从 eclipse 导出了一个 apk。如果我将它复制到手机的 SD 卡,我可以毫无问题地安装它。

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

尝试通过手机(Galaxy S)浏览器下载时,我得到:“下载失败”。

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

我在 mime.types 中设置了 mime 类型 application/vnd.android.package-archive,重新启动 apache,结果仍然相同。也试过:

<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)

我可以从安卓市场下载和安装应用程序。我怀疑 apache 没有发送 mime 类型,但这只是黑暗中的一个镜头。如何解决问题并能够从我的网络服务器安装 APK?(或至少检查 apache 是否发送正确的带有 mime 类型的标头)

Any help will be appreciated.

任何帮助将不胜感激。

采纳答案by Ognyan

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

毕竟我发现问题的部分原因是 CommonsWare 的建议。

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.

我用来下载 apk 的目录受 simpe auth 保护。手机的浏览器在浏览时正确询问(一次)用户名/密码,但显然在尝试下载文件时忘记发送身份验证信息,这会导致 401 Unauthorized。

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

解决方案:从该目录中删除基本身份验证或为 apk 使用另一个不受保护的目录。

回答by Vasil Popov

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

如果将 .apk 扩展名添加到 apache 的 mime 配置中会更好。看看这个例子: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:

您可以找到“apk”记录并将该行复制到服务器上的文件 /etc/mime.types 中:

application/vnd.android.package-archive     apk

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

还要将此添加到 /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. ;)

(还有一些其他的 AddType-s,请务必放在它们之后)。从这里开始,您不必在标签中为 apk 的 mime 类型添加任何内容,服务器将处理此问题。;)

UPDATE: fixed a bug in AddType line

更新:修复了 AddType 行中的错误

回答by CommonsWare

Use curlto 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.

使用curl测试Web服务器,以确保它是响应HTTP请求,并返回正确的MIME类型。此外,例如您的服务器日志以查看正在记录的错误。

回答by JEX725

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 .apkHope it helps.

有时您无法访问 /etc/mime.types 等 apache 配置文件,尤其是在共享服务器上。您可以在根目录中创建文件 .htaccess(如果已经存在则打开)并添加以下字符串: AddType application/vnd.android.package-archive .apk希望它有所帮助。