0

当我开始从我们的网站在手机(Google Nexus)上下载 .apk 时,会发生以下情况:

1.我得到代码中的重定向链接 2.开始下载应用程序,但下载完成后,我得到错误下载未完成(失败) 3.我得到错误页面,说页面不可用,我可以上网

这是下载链接的格式:/game.do?x=&y=&z=

早些时候,我能够下载具有相同代码的应用程序。.

如果您对问题有任何想法,请告诉我。

谢谢

Rakesh .apk 大小从 500KB 到 5MB 不等

4

1 回答 1

0

使用以下代码从服务器下载 apk 文件

private void download(){
    try {
        URL url = new URL("url from apk file is to be downloaded");
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.setDoOutput(true);
        urlConnection.connect();

        File sdcard = Environment.getExternalStorageDirectory();
        File file = new File(sdcard, "filename.ext");

        FileOutputStream fileOutput = new FileOutputStream(file);
        InputStream inputStream = urlConnection.getInputStream();

        byte[] buffer = new byte[1024];
        int bufferLength = 0;

        while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
            fileOutput.write(buffer, 0, bufferLength);
        } 
        fileOutput.close();

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

并参考下面的链接从 url 下载和安装 apk 文件。

下载并安装 APK 文件

于 2012-07-07T11:04:08.107 回答