Your trying to pull the file from a URI that doesn't exist as Android is Linux based and the file system isn't the same as windows. I suggest you use the FileSystemHelpers to load your file. Dependant on where your file is, if it's in the Resources/Raw folder odd a lot easier to find. You can read more here. https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/storage/file-system-helpers?view=net-maui-9.0&tabs=android I personally use the PDF viewer from Sync fusion which is free and does all the hard work for you rather than use the browser.
Getting issue while view pdf in .net maui webview for android platform
Thombre, Ashish
130
Reputation points
InitializeComponent();
Microsoft.Maui.Handlers.WebViewHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
#if ANDROID
handler.PlatformView.Settings.JavaScriptEnabled = true;
handler.PlatformView.Settings.AllowFileAccess = true;
handler.PlatformView.Settings.AllowFileAccessFromFileURLs = true;
handler.PlatformView.Settings.AllowUniversalAccessFromFileURLs = true;
#endif
});
string path;
using (var http = new HttpClient())
{
var stream = await http.GetStreamAsync("https://www.africau.edu/images/default/sample.pdf");
path = Path.Combine(FileSystem.AppDataDirectory, "sample.pdf");
using Stream streamToWriteTo = File.Open(path, FileMode.Create);
await stream.CopyToAsync(streamToWriteTo);
}
if (File.Exists(path))
{
#if ANDROID
Android.Net.Uri uri = Android.Net.Uri.FromFile(new Java.IO.File(path));
string pdfFilePath = string.Format("file:///android_asset/web/viewer.html?file={0}", uri);
pdfWebView.Source = new UrlWebViewSource { Url = pdfFilePath };
#endif
}
i am using above code but getting issue web page not available, please refer attached video.
i want to download pdf and show it in webview for android platform
Developer technologies | .NET | .NET MAUI
Developer technologies | .NET | .NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.