简体   繁体   English

无法从我们的网站在Android手机上下载.apk

[英]Not Able to download .apk on Android handset from our site

When i start downloading .apk on mobile handset(Google Nexus) from our site,following thing happens: 当我开始从我们的网站上通过手机(Google Nexus)下载.apk时,发生以下情况:

1.I get redirection link which is in the code 2.Start downloading the application but after download gets complete ,i get error download not completed(failed) 3. I get error page, saying page is not available,where as i an able to access net 1.我得到代码中的重定向链接2.开始下载应用程序,但是下载完成后,我得到错误下载未完成(失败)3.我得到错误页面,说该页面不可用,我可以上网

here is the format of link to down load:/game.do?x=&y=&z= 这是下载链接的格式:/game.do?x =&y =&z =

Earlier i was able to download applications with same code. 之前,我能够使用相同的代码下载应用程序。 .

If you have any idea about the problem please let me know. 如果您对问题有任何想法,请告诉我。

Thanks 谢谢

Rakesh .apk size varies from 500KB to 5MB Rakesh .apk大小从500KB到5MB不等

Use below Code for download apk file from server 使用以下代码从服务器下载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();
    }
}

And Refer below link for download and install apk file from url. 并参考以下链接以从URL下载并安装apk文件。

Download & Install APK File 下载并安装APK文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM