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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:18:04+00:00 2026-06-05T08:18:04+00:00

I am developing an application to download pdf file in sd card with the

  • 0

I am developing an application to download pdf file in sd card with the url entered in edittext , after clicking the submit button.

       Button b = (Button)findViewById(R.id.button1);
       final EditText ed = (EditText)findViewById(R.id.editText1);
       b.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
         String URL  = ed.getText().toString();
          WebView web1 =(WebView)findViewById(R.id.webview);
          web1.getSettings().setJavaScriptEnabled(true);
           web1.loadUrl(URL);  
           }
          });
  • 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-05T08:18:07+00:00Added an answer on June 5, 2026 at 8:18 am

    Below code may help you –

    public class DownloaderThread extends Thread
    {
            // constants
            private static final int DOWNLOAD_BUFFER_SIZE = 4096;
    
            // instance variables
            private AndroidFileDownloader parentActivity;
            private String downloadUrl;
    
            /**
             * Instantiates a new DownloaderThread object.
             * @param parentActivity Reference to AndroidFileDownloader activity.
             * @param inUrl String representing the URL of the file to be downloaded.
             */
            public DownloaderThread(AndroidFileDownloader inParentActivity, String inUrl)
            {
                    downloadUrl = "";
                    if(inUrl != null)
                    {
                            downloadUrl = inUrl;
                    }
                    parentActivity = inParentActivity;
            }
    
            /**
             * Connects to the URL of the file, begins the download, and notifies the
             * AndroidFileDownloader activity of changes in state. Writes the file to
             * the root of the SD card.
             */
            @Override
            public void run()
            {
                    URL url;
                    URLConnection conn;
                    int fileSize, lastSlash;
                    String fileName;
                    BufferedInputStream inStream;
                    BufferedOutputStream outStream;
                    File outFile;
                    FileOutputStream fileStream;
                    Message msg;
    
                    // we're going to connect now
                    msg = Message.obtain(parentActivity.activityHandler,
                                    AndroidFileDownloader.MESSAGE_CONNECTING_STARTED,
                                    0, 0, downloadUrl);
                    parentActivity.activityHandler.sendMessage(msg);
    
                    try
                    {
                            url = new URL(downloadUrl);
                            conn = url.openConnection();
                            conn.setUseCaches(false);
                            fileSize = conn.getContentLength();
    
                            // get the filename
                            lastSlash = url.toString().lastIndexOf('/');
                            fileName = "file.bin";
                            if(lastSlash >=0)
                            {
                                    fileName = url.toString().substring(lastSlash + 1);
                            }
                            if(fileName.equals(""))
                            {
                                    fileName = "file.bin";
                            }
    
                            // notify download start
                            int fileSizeInKB = fileSize / 1024;
                            msg = Message.obtain(parentActivity.activityHandler,
                                            AndroidFileDownloader.MESSAGE_DOWNLOAD_STARTED,
                                            fileSizeInKB, 0, fileName);
                            parentActivity.activityHandler.sendMessage(msg);
    
                            // start download
                            inStream = new BufferedInputStream(conn.getInputStream());
                            outFile = new File(Environment.getExternalStorageDirectory() + "/" + fileName);
                            fileStream = new FileOutputStream(outFile);
                            outStream = new BufferedOutputStream(fileStream, DOWNLOAD_BUFFER_SIZE);
                            byte[] data = new byte[DOWNLOAD_BUFFER_SIZE];
                            int bytesRead = 0, totalRead = 0;
                            while(!isInterrupted() && (bytesRead = inStream.read(data, 0, data.length)) >= 0)
                            {
                                    outStream.write(data, 0, bytesRead);
    
                                    // update progress bar
                                    totalRead += bytesRead;
                                    int totalReadInKB = totalRead / 1024;
                                    msg = Message.obtain(parentActivity.activityHandler,
                                                    AndroidFileDownloader.MESSAGE_UPDATE_PROGRESS_BAR,
                                                    totalReadInKB, 0);
                                    parentActivity.activityHandler.sendMessage(msg);
                            }
    
                            outStream.close();
                            fileStream.close();
                            inStream.close();
    
                            if(isInterrupted())
                            {
                                    // the download was canceled, so let's delete the partially downloaded file
                                    outFile.delete();
                            }
                            else
                            {
                                    // notify completion
                                    msg = Message.obtain(parentActivity.activityHandler,
                                                    AndroidFileDownloader.MESSAGE_DOWNLOAD_COMPLETE);
                                    parentActivity.activityHandler.sendMessage(msg);
                            }
                    }
                    catch(MalformedURLException e)
                    {
                            String errMsg = parentActivity.getString(R.string.error_message_bad_url);
                            msg = Message.obtain(parentActivity.activityHandler,
                                            AndroidFileDownloader.MESSAGE_ENCOUNTERED_ERROR,
                                            0, 0, errMsg);
                            parentActivity.activityHandler.sendMessage(msg);
                    }
                    catch(FileNotFoundException e)
                    {
                            String errMsg = parentActivity.getString(R.string.error_message_file_not_found);
                            msg = Message.obtain(parentActivity.activityHandler,
                                            AndroidFileDownloader.MESSAGE_ENCOUNTERED_ERROR,
                                            0, 0, errMsg);
                            parentActivity.activityHandler.sendMessage(msg); 
                    }
                    catch(Exception e)
                    {
                            String errMsg = parentActivity.getString(R.string.error_message_general);
                            msg = Message.obtain(parentActivity.activityHandler,
                                            AndroidFileDownloader.MESSAGE_ENCOUNTERED_ERROR,
                                            0, 0, errMsg);
                            parentActivity.activityHandler.sendMessage(msg); 
                    }
            }
    
    }
    

    Above code extracted from this Existing project. Don’t forget to give the required permission for Internet

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

Sidebar

Related Questions

I am developing an web application which can upload/download a file from client to
I have been developing an application which needs to download a file from the
I am developing media player and my application download mp3 file from server .
I'm Developing an iPad application where I need to download file from the Webservice
I'm developing an application that will Download another apk file, and asks for it's
I am developing a windows phone application which allows user to download files from
I am developing a php application which my customers will download and install on
I am developing an application where from several screens user has to download a
I'm developing mobile application which will be able to download/upload mobile phone book contact
I am developing an application which download files from internet; the files are mainly

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.