3

I have a webview in my app that is working fine, i can navigate and submit normal forms, click on href, etc. I have one issue with forms that go to a php file that i use to download file.

The code of the php is:

$indice=$_POST['indice'];
$sql_file="SELECT * FROM files WHERE indice=".$indice;
$file=$connect->query($sql_file);
$row=$file->fetch_assoc();
header("Content-Type: {$row['type']}\n");
header("Content-Disposition: attachment; filename=\"{$row['name']}\"\n");
header("Content-Length: {$row['size']}\n");
echo base64_decode($row['data']);

I try to manage the download with the function:

public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)

But is not working because is a submit of a form show this function is not executed, it only execute when you click in a href or similar.

With the function "onPageStarted" i can get the url so i know if i submitted the download form but i cant see the post data.

How can i manage the download? In IOS the webclient did automatically and even load the PDF in the webclient.

Best Regards.

Roke
  • 329
  • 1
  • 3
  • 16
  • with [downloadmanager](https://developer.android.com/reference/android/app/DownloadManager.html) you can manage file downlaod – Mehran Zamani Mar 04 '17 at 15:45
  • Possible duplicate of [Download File inside WebView](http://stackoverflow.com/questions/10069050/download-file-inside-webview) – KlevisGjN Mar 04 '17 at 15:49
  • I try with a download listener but didnt execute. I debug with a Log.d and never show. So i cant handle with a download listener and dont know why – Roke Mar 04 '17 at 16:49
  • Hi, did you ever solve this? I'm battling with it, nearly solved the issue but wondering if you found a simpler way. – Garcon Jun 04 '20 at 16:20

1 Answers1

-2

You just need your php file to download the file when submitting and add download listener to Webview in your application.

Anyway your post is a possible duplicate of the following:

1. Autostart file download after form submission
2. Download File inside WebView

Community
  • 1
  • 1
KlevisGjN
  • 681
  • 2
  • 10
  • 16