I have a WebView in a MAUI app that generally works, but whenever I click a link on Android that is supposed to download a file (link returns a Content-Disposition header) nothing happens.
How is this supposed to be implemented? I can't find any documentation.
<WebView
x:Name="WebView"
Source=".." />
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
protected override bool OnBackButtonPressed()
{
base.OnBackButtonPressed();
if (WebView.CanGoBack)
{
WebView.GoBack();
return true;
}
else
{
base.OnBackButtonPressed();
return true;
}
}
}
Related question for iOS: Download files in MAUI iOS WebView
For the android, you can try to add a DownloadListener to the webview. I have testd it and the file can download successfully.
Create the custom downloadlistener class in the \Platforms\Android:
In the page's xaml:
And set the listener for the webview in the Page.cs: