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

  • SEARCH
  • Home
  • 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 8661663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:33:05+00:00 2026-06-12T16:33:05+00:00

I need to download by program an .apk file then launching its activity. The

  • 0

I need to download by program an .apk file then launching its activity.
The code I am using is the following

private String downloadFile(String sourceURL, String destinationPath)
    {
        try {
            URL url = new URL(sourceURL);
            URLConnection connection = url.openConnection();
            connection.connect();

            // download the file
            InputStream input = new BufferedInputStream(url.openStream());
            OutputStream output = new FileOutputStream(destinationPath);

            byte data[] = new byte[1024];
            int count;
            while ((count = input.read(data)) > 0) {
                output.write(data, 0, count);
            }

            output.flush();
            output.close();
            input.close();

// EDITED here: Make the file rw, otherwise the apk file will not be installed
Runtime.getRuntime().exec(“chmod 666 ” + destinationPath);

            message = "OK";
        }
        catch (MalformedURLException e) {
            message = "Malformed URL error: " + e.getMessage();
        }
        catch (ProtocolException e) {
            message = "Protocol exception error: " + e.getMessage();
        }
        catch (FileNotFoundException e) {
            message = "File not found error: " + e.getMessage();
        }
        catch (IOException e)   {
            e.printStackTrace();
            message = "Failed to download the file : " + e.getMessage();
        }
        return message;
    }

I mention that I call the method first for a text file, then for an apk file. Each time I process the files locally, therefore, somehow I know what’s going wrong or not. In this way I know that the text file is downloaded correctly. But the .apk file is corrupted. Because I develop locally, with access to DDMS and localhost (the IP: 10.0.2.2) I can firmly state that the culprit is the code above. When I artificially replace the ‘downloaded’ file, through DDMS, with the original .apk file, all processing that follows is Ok. In addition, I have byes difference when I compare the original and the downloaded .apk files.
What am I doing wrong?
Thanks
PS: Searching, I realized that, while is a popular issue, there is no consistent answer to it. In my case I identified it as purely a download method issue.

  • 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-12T16:33:06+00:00Added an answer on June 12, 2026 at 4:33 pm

    Please see above the answer under the EDITED line. Implemented, works fine, that may help others

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

Sidebar

Related Questions

I need a java program to download a series of file from a web
I need to write code to download and run a program, e.g. notepad++ (npp.5.9.3.Installer.exe)
I have a program (temptrack) where I need to download weather data every x
I need to download a large file (2 GB) over HTTP in a C# console
I need to download file from FTP server and make some changes on it
I need to download Gmail emails using php api. there APIs for google. i
I need to download one file from an url that i give from an
I need a free and quick to download program that can test a connection
I'm creating a program where I need to search an FTP server and download
I need to execute a program and retrieve its stdout output in c++. I'd

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.