-3
 mWebView2 = new WebView(WEB2.this);
        mWebView2.getSettings().setJavaScriptEnabled(true);
        WebSettings webSettings = mWebView2.getSettings();
        webSettings.setJavaScriptEnabled(true);
mWebView2.goBack();
        mWebView2.goBackOrForward(20);
        mWebView2.setInitialScale(1);
        mWebView2.getSettings().setUseWideViewPort(true);
        mWebView2.getSettings().setDisplayZoomControls(true);

        mWebView2.setWebViewClient(new WebViewClient());
        mWebView2.loadUrl("https://docs.google.com/gview?embedded=true&url=http://www.uobabylon.edu.iq/uobColeges/ad_downloads/4_25835_742.pdf");
        setContentView(mWebView2);

I would like to create a Button to download any online pdf file, and when click on this Button ot start the download.

I executed this code to open pdf file , but i want to add a Button to download that pdf

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Salha
  • 1
  • 1

3 Answers3

0

In your Android application, on click of button open the url in the web browser using Intent. Like :

String url = "http://www.website.com/filename.pdf";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

Once this code get executed it will automatically download the file in your device memory.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • down.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url="http://uobabylon.edu.iq/uobColeges/ad_downloads/4_25835_742.pdf"; Intent i=new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); – Salha Mar 10 '17 at 13:48
0

see this accepted answer how to download file from url?Download a file with Android, and showing the progress in a ProgressDialog

you not need webview to load file if you want just download and save it

Community
  • 1
  • 1
Rajesh
  • 2,618
  • 19
  • 25
0

Just simply use this method it will ask to open your browser to download your file

       yourButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent download = new Intent(Intent.ACTION_VIEW);
                String url = "YOUR FILE URL";
                download.setData(Uri.parse(url));
                startActivity(download);
            }
        });

hope it helps you happy coding!

Kunal Dudka
  • 467
  • 1
  • 6
  • 14