Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:42:46+00:00 2026-06-17T09:42:46+00:00

I am having a problem with android 4.0 or higher when, I’m Trying to

  • 0

I am having a problem with android 4.0 or higher when, I’m Trying to download a file from a URL, It works fine in android Galaxy Y 2.3 / 2.2 but when I use the same code for Galaxy S3(4.1.2) the download starts but it doesn’t finish.

Code:

 public void update() {
    Log.d(TAG, "Método para fazer a atualização iniciado.");
    try {
        Log.d(TAG, "Conectando com a internet...");
        URL url = new URL(
                url);
        HttpURLConnection c = (HttpURLConnection) url.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);
        c.connect();

        Log.d(TAG, "Iniciando arquivo...");
        String PATH = Environment.getExternalStorageDirectory()
                + "/test/Update/";
        File file = new File(PATH);
        file.mkdirs();
        File outputFile = new File(file, "test.apk");
        FileOutputStream fos = new FileOutputStream(outputFile);

        Log.d(TAG, "Iniciando Stream...");
        InputStream is = c.getInputStream();

        Log.d(TAG, "Iniciando o download...");
        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ((len1 = is.read(buffer)) != -1) {
            fos.write(buffer, 0, len1);
        }
        fos.close();
        is.close();

        Log.d(TAG, "Iniciando instalador...");
        final Intent promptInstall = new Intent(Intent.ACTION_VIEW);
        promptInstall.setDataAndType(Uri.fromFile(new File(PATH + "test.apk")),"application/vnd.android.package-archive");
        promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(promptInstall);
        Log.d(TAG, "Instalador iniciado com sucesso!");
    } catch (MalformedURLException e) {
        Log.e(TAG, "Malformed URL. Mensagem: " + e.getMessage()
                + " Causa: " + e.getCause());
    } catch (IOException e) {
        Log.e(TAG, "IOException. Mensagem: " + e.getMessage() + " Causa: "
                + e.getCause());
    } catch (Exception e) {
        Log.e(TAG, "Exception. Mensagem: " + e.getMessage() + " Causa: "
                + e.getCause());
    }
}

Obs:There is no Error, It just start the download and stop it.
File size : 126,188 bytes and in the Galaxy S3 6,403 bytes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:42:46+00:00Added an answer on June 17, 2026 at 9:42 am

    Use AsyncTask to make your request.

    AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to install android sdk, but I am having a problem. First,
I am having problem with download my android application from my own web server.
I'm having a problem with android. I'm setting the Weight parameter in Java, but
Possible Duplicate: Android Launch an application from another application I am having a problem
I am having problem with limiting edittext length in android. Everything works perfect except
I having a problem with my android client trying to post a JSON class
I am having a problem calling string values from the strings.xml resource in Android.
I've been trying to make a customize video player but I'm having problem with
I am having a problem doing a simple http post request from my android
I'm having problem posting a share to LinkedIn from my Android application. I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.