简体   繁体   中英

How to download a pdf from an Android Webview?

I have an application that launches a webivew . When I click on the PDF links in the webview , download of that PDF should start. I am able to do this with the following code.

view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

Here the moment the download starts my current webview activity is closed, as I give startActivity() .

But I want user to be on the webview itself and download should start in the background without vanishing the webview . What is the way around for that? Kindly help.

You can do one thing. The moment the PDF download starts, then see to it that your webview activity is prevented from onDestroy() or finish().

Then u can start the download in background and also retain the Webview activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM