Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Can't use HTTPS to download from website with early Android versions

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 313
    Answer it

    I have an Android app which downloads simple text files from my website using HTTPS. I have been testing it on emulators for every version from API18 onwards, and on real devices running API18 and API28. It works fine for API21 and above, but for API 18 (emulator and real device) and for API19 it fails - the download just hangs.

    The app uses DownloadManager, but I have also tried some code using HttpsURLConnection. This is the code:

    Runnable runnable = new Runnable() {
            public void run() {
                try {
                    String line;
                    URL url = new URL("https://..website../list.txt");
                    HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();
                    BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
                    StringBuilder outLine = new StringBuilder();
                    while ((line = br.readLine()) != null) {
                        outLine.append(line);
                    }
                    testResult=outLine;
                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_LONG).show();
                }
            }
        };
        Thread mythread = new Thread(runnable);
        mythread.start();

    As with DownloadManager, this works ok on API21 or newer, but not on API18 or API19.

    I have read some old stuff that seems to talk about problems with HTTPS on old Android versions but it wasn't clear what the issues were.

    Can anyone help a novice developer to understand the problem, and tell me how to download using HTTPS on Android version API19 and older?

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: