I intend to load local HTML files into a Xamarin Forms WebView.
I've added the HTML files to the assets/HTML folder, and its Build Action is set to AndroidAsset.
I've implemented the base URL finder interface:
public class BaseUrl_Android:IBaseUrl
{
public string Get()
{
return "file:///android_asset/";
}
}
I have tried to load the file from the using this in the shared portable code:
string baseUrl = DependencyService.Get().Get();
string url = baseUrl + "HTML/local.html";
myWebView.Source = url;
I also tried a custom WebViewRenderer, and used this code:
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
// lets get a reference to the native control
var webView = (global::Android.Webkit.WebView)Control;
// do whatever you want to the WebView here!
webView.LoadUrl(DependencyService.Get().Get()+"HTML/local.html");
webView.SetWebViewClient(new MyWebViewClient());
}
With both solutions I get an error:
What else should I try?