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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:42:45+00:00 2026-06-03T16:42:45+00:00

The Url of my path is something like this www.sample.com/sample/1234 . When you click

  • 0

The Url of my path is something like this www.sample.com/sample/1234.
When you click on the path it downloads a file something like this

Sample_hello_sample.epub

I couldn’t make my app work with this download.

Here’s my code:

private class InsideWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.contains("sample")) {
            startDownload(url);
            return true;
        }

        //...?

        view.loadUrl(url);
        return true;
        }
    }

    @Override
    public void onBackPressed() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Are you sure you want to exit?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       Gutenbergmain.this.finish();
                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                   }
               });
        AlertDialog alert = builder.create();
        alert.show();
    }

    private void startDownload(String url) {
        new DownloadFileAsync().execute(url);
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_DOWNLOAD_PROGRESS:
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setMessage("Downloading file..");
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgressDialog.setCancelable(false);
            mProgressDialog.show();
            return mProgressDialog;

        default:
            return null;
        }
    }

    @Override
    protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
        if (id == DIALOG_DOWNLOAD_PROGRESS)
            mProgressDialog.setProgress(0);
    }

    class DownloadFileAsync extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            showDialog(DIALOG_DOWNLOAD_PROGRESS);
            mProgressDialog.setProgress(0);
        }

        @Override
        protected String doInBackground(String... aurl) {
            int count;

            try {
                URL url = new URL(aurl[0]);

                URLConnection conexion = url.openConnection();
                conexion.connect();

                int lenghtOfFile = conexion.getContentLength();
                Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

                String path = url.getPath();
                String idStr = path.substring(path.lastIndexOf('/') + 1);

                String fileName = idStr;

                File sdCard = Environment.getExternalStorageDirectory();
                File dir = new File (sdCard.getAbsolutePath() + "/Sample/epub");
                dir.mkdirs();

                File file = new File(dir, fileName);

                InputStream input = new BufferedInputStream(url.openStream());
                FileOutputStream f = new FileOutputStream(file);

                //InputStream input = new BufferedInputStream(url.openStream());
                //OutputStream output = new FileOutputStream("/sdcard/" + fileName);

                byte data[] = new byte[1024];

                long total = 0;

                while ((count = input.read(data)) != -1) {
                    total += count;
                    publishProgress(""+(int)((total*100)/lenghtOfFile));
                    f.write(data, 0, count);
                    //output.write(data, 0, count);
                }

                f.flush();
                f.close();

                //output.flush();
                //output.close();

                input.close();
            } catch (Exception e) {}

            return null;
        }

        protected void onProgressUpdate(String... progress) {
             Log.d("ANDRO_ASYNC",progress[0]);
             mProgressDialog.setProgress(Integer.parseInt(progress[0]));

        }

        @Override
        protected void onPostExecute(String unused) {
            dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
        }
    }
}
  • 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-03T16:42:47+00:00Added an answer on June 3, 2026 at 4:42 pm

    you must edit your AndroidManifest.xml file. for example.

    <intent-filter >
       <action android:name="android.intent.action.VIEW" />
       <category android:name="android.intent.category.BROWSABLE" />
       <category android:name="android.intent.category.DEFAULT" />
       <data android:mimeType="application/*"  />
       <data android:host="*" /> 
       <data android:pathPattern=".*\\.epub" /> 
    </intent-filter>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Android webview, you could pass something like this file:///android_asset/myfile.txt or this http://www.mysite.com/t.html and
i have something like this: $(#btn).click(function (event) { $.getJSON(url, function (data) { // i
I need help for this. The path for my URL is something like this
The docs for django.core.files.File imply I can do this: print File(open(path)).url but the File
I have something like: MEDIA_ROOT = '/home/httpd/foo/media/' MEDIA_URL = 'http://www.example.org/media/' (...) file = models.FileField(upload_to='test')
I have this piece of code: <table style=background-image: url(path/to_image.png)> And when I load it
What would the relative path of the following url be? http://domain.com/wp-content/themes/themename/images/breadcrumb_sep.png
Basically I would like to do something like this at the top of my
When I am adding a static view like this: cfg = config.Configurator(...) cfg.add_static_view(name='static', path='MyPgk:static')
I would like to convert an absolute path into a relative path. This is

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.