0

I want to ask a question about downloading Apk with programmatically in Android. When i give url over http, Apk is not downloaded to my telephone. But changing URL with https works to download the APK with successufully. What is the reason of this? Also, downloading url is hidden over https website.

        try {

            URL url = new URL("http://....../LinaSoft_1_0_4.Apk");
            HttpURLConnection c = (HttpURLConnection) url.openConnection();
            c.connect();


            String PATH = Environment.getExternalStorageDirectory()+"/Download/";
            File file = new File(PATH);
            file.mkdirs();

            File outputFile = new File(file,"LinaSoft_1_0_4.apk");
            Log.d("output",outputFile.toString());

            File dosyalar = new File(PATH);


            FileOutputStream fos = new FileOutputStream(outputFile);
            InputStream is = c.getInputStream();
            int total_size = c.getContentLength();


            byte[] buffer = new byte[1024];
            int len1 = 0;
            int per = 0;
            int downloaded=0;

            while ((len1 = is.read(buffer)) != -1) {
                fos.write(buffer, 0, len1);
                downloaded +=len1;
                per = (int) (downloaded * 100 / total_size);
                publishProgress(per);
            }
            fos.close();
            is.close();
            Log.d("Boyut",String.valueOf(total_size));
            OpenNewVersion(PATH);

            flag = true;
        } catch (IOException e) {
            Log.d( "Update Error: " , e.getMessage());
            flag = false;
        }
        return flag;

    }
Gökhan Aldanmaz
  • 113
  • 1
  • 14
  • Related [What is the difference between http and https in programming](https://stackoverflow.com/q/14912915/7666442) and [Difference between http and https](https://stackoverflow.com/q/8375134/7666442) – AskNilesh Jan 23 '19 at 06:44
  • 2
    Because your remote service doesn't allow HTTP protocol, only https. – just Jan 23 '19 at 06:48
  • *"Also, downloading url is hidden over https website."* - Not sure what you mean by that. – Stephen C Jan 23 '19 at 09:27
  • Downloadable url is embedded in a Web site with having HTTPS. But URL starts with http protocol, two things are also independent from each other. We fetched URL from FTP server. Web site is related with this situation? Because the url have worked before and SSL can be affect this? – Gökhan Aldanmaz Jan 24 '19 at 00:50

1 Answers1

1

Because your remote service doesn't allow HTTP protocol, only https.

just
  • 1,900
  • 4
  • 25
  • 46
  • This is the most likely explanation ... but others are possible. For example, crazy firewall rules, a broken server, 3xx redirection from http to https not working. – Stephen C Jan 23 '19 at 09:25
  • Yes, there are a lot of other possible causes, but the OP doesn't describe the environment. – just Jan 23 '19 at 09:31