Android 从浏览器下载和安装 apk 的 Html 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12097527/
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 09:43:51  来源:igfitidea点击:

Html page to download and install apk from browser

androidbrowserandroid-intentinstallationapk

提问by Christian

I have an app that will be installed by the user from a public webserver (outside android market).

我有一个应用程序将由用户从公共网络服务器(Android 市场之外)安装。

So I hosted the apk in webserver and instructed the users to type the url to download the file and then "open" the downloaded file to install it.

因此,我将 apk 托管在网络服务器中,并指示用户键入 url 以下载文件,然后“打开”下载的文件进行安装。

But, almost 100% of users are having difficulties to do those simple tasks (they're are not familiar with technology...).

但是,几乎 100% 的用户都难以完成这些简单的任务(他们不熟悉技术......)。

So, I decided to make a webpage that will simplify the task. The page contains a single big button that will:

所以,我决定制作一个可以简化任务的网页。该页面包含一个大按钮,它将:

  • Donwload the apk;
  • After download finish, start "Android's Install Dialog" to install the downloaded apk;
  • 下载apk;
  • 下载完成后,启动“Android's Install Dialog”安装下载的apk;

Dowloading file is pretty easy, but now my problem is to open the "Install dialog" from browser!

下载文件很容易,但现在我的问题是从浏览器打开“安装对话框”!

I'm totally newbie about html/javascript and I don't know how to do it (or even if this is possible).

我完全是 html/javascript 的新手,我不知道该怎么做(或者即使这是可能的)。

回答by Ridcully

Normally, you just link to the .apkfile. When the user clicks on such a link, the .apkfile is downloaded and the installation is automatically started (with a dialog like 'do you want to install this application').

通常,您只需链接到.apk文件。当用户单击此类链接时,将.apk下载文件并自动开始安装(带有类似“您要安装此应用程序吗”的对话框)。

So, just <a href="yourdomain.com/yourapp.apk">Download and install...</a>.

所以,只是<a href="yourdomain.com/yourapp.apk">Download and install...</a>

Important! This only works if your users allow installation from 'Unknown sources' in settings/security.

重要的!这仅在您的用户允许从设置/安全中的“未知来源”安装时才有效。

回答by Maxim

If browser is written not by you, then it doesn't know what to do with downloaded apk file. Ask user to download something like EasyInstall to install side-loaded apks or place you apk on Google Play. Google Play app on the device knows how to install apk.

如果浏览器不是您编写的,那么它不知道如何处理下载的 apk 文件。要求用户下载诸如 EasyInstall 之类的东西来安装侧面加载的 apk 或将您的 apk 放在 Google Play 上。设备上的 Google Play 应用程序知道如何安装 apk。

-- True at the time of writing: Aug. 2012

-- 在撰写本文时为真:2012 年 8 月

回答by Paul Sturm

You need to ensure your webserver that is going to deliver the APK sets the MIME type properly. It should be application/vnd.android.package-archivefor .apk files.

您需要确保将提供 APK 的网络服务器正确设置 MIME 类型。它应该application/vnd.android.package-archive用于 .apk 文件。