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 6662297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:22:29+00:00 2026-05-26T02:22:29+00:00

I make an application , this can download file form server. use this code

  • 0

I make an application , this can download file form server.

use this code >>>

public int startDownload(String url, String filename) {
// create url connector
URL u;
byte[] buffer = new byte[1024];
try {
  u = new URL(url + filename);
  HttpURLConnection c = (HttpURLConnection) u.openConnection();
  c.setRequestMethod("GET");
  c.setDoOutput(true);
  c.connect();
  InputStream in = c.getInputStream();
  m_lMaxDownloadSz = c.getContentLength();
  FileOutputStream f = new FileOutputStream(new File(FILE_PATH, filename));

  m_bCancelDownload = false;
  m_lCurrentDownloadSz = 0;
  int len = 0;
  while ((len = in.read(buffer, 0, 1024)) > 0) {

    // if download is canceled.
    if (m_bCancelDownload) {
      f.close();
      c.disconnect();
      return FILE_DOWNLOAD_CANCELED;
    }
    if (knot++ >= PROGRESS_STEP) {
      knot = 0;
      myProgressDialog.setProgress(GetDownloadStatus());
    }
    f.write(buffer, 0, len);
    m_lCurrentDownloadSz += len;
  }

  f.close();
  c.disconnect();

} catch (Exception e) {
  return FILE_DOWNLOAD_FAILED;
}

if (GetDownloadStatus() == 100) {
  return FILE_DOWNLOAD_FINISHED;
} else {
  return FILE_DOWNLOAD_FAILED;
}

}

and I want to use with PHP force download , but it not work , ordinary it use with file path like ‘app/aaa.apk’ it work! ,and I change to PHP file like ‘php/forcedl.php’ it not work.

I needs to use with php force download, How do I use?

ps. i have little english language skill , cause english language is not my main language

thank you

  • 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-05-26T02:22:30+00:00Added an answer on May 26, 2026 at 2:22 am

    I discover for my answer
    android-Java Code
    __example:

            byte[] buffer = new byte[1024];         
            String url = "http://www.bla-bla.com/forcedownload.php"
    
    
                DefaultHttpClient client = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(url);
                try {
                    HttpResponse execute = client.execute(httpGet);
                    InputStream content = execute.getEntity().getContent();
    
                    filesize = execute.getEntity().getContentLength();
                    fileOutput = new FileOutputStream(new File(FILE_PATH, "file_copyformserver.apk"));
    
                     while ((len = content.read(buffer, 0, 1024)) > 0) {
                         fileOutput.write(buffer, 0, len);
                         Thread.sleep(100);
                     }
    
                    fileOutput.close();
    
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
    

    php file
    __example:

          $file = '/home/bla-bla/domains/bla-bla.com/file/file.apk'; //not public folder
          if (file_exists($file)) {
             header('Content-Description: File Transfer');
             header('Content-Type: application/vnd.android.package-archive');
             header('Content-Disposition: attachment; filename='.basename($file));
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
             header('Content-Length: ' . filesize($file));
             ob_clean();
             flush();
             readfile($file);
             exit;
         }
    

    this is short code , sorry if cannot run. 🙂

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

Sidebar

Related Questions

I would like to make a simple desktop application to learn this kind of
My application links against libsamplerate.a. I am doing this to make distributing the final
How do you make your application multithreaded ? Do you use asynch functions ?
How do I make my application always use English when displaying win32/.net exceptions messages?
I have a application, and had to create another .h and .m file. This
How can I make a SQL Compact 2008 application for the desktop? I know
I'm trying to develop a settings application whererby a developer can download a zip
I worked on a nice force download file script which purpose is to make
My application reads an Access database file that can be updated at runtime by
I make an Application in java and draw rectangle. When I search from combobox

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.