Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Xamarin forms web renderer for android

$
0
0

Hi,

Im trying to render my web view. I want to cache web page data to sqlite. How can i do that?

I wrote these code :

`[assembly: ExportRenderer(typeof(WebAppView), typeof(WebAppViewRenderer))]
namespace Wrapper.Android
{
public class WebAppViewRenderer :WebRenderer
{

    public WebAppViewRenderer()
    {

        System.Diagnostics.Debug.WriteLine("WebAppViewRenderer()");



    }

    protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement == null)
        {


            var webView = new global::Android.Webkit.WebView(this.Context);
            webView.Settings.JavaScriptEnabled = true;
            webView.SetWebViewClient(new MyWebViewClient(this));
            webView.ScrollbarFadingEnabled = false;
            webView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
            webView.Settings.SetAppCacheEnabled(true);
            webView.Settings.SetAppCacheMaxSize(8 * 1024 * 1024);
            webView.Settings.SetAppCachePath("/data/data/" + "myapp" + "/cache");
            webView.Settings.CacheMode = CacheModes.CacheElseNetwork;
            webView.Settings.AllowFileAccess = true;


        }
    }

}

public class MyWebViewClient : WebViewClient
{
    public MyWebViewClient(WebAppViewRenderer webAppViewRenderer)
    {

    }
    bool shouldOverride = false;  
    public override bool ShouldOverrideUrlLoading(global::Android.Webkit.WebView view, string url)
    {
        if (url.StartsWith("https://"))
        { //NON-NLS  
            // DO SOMETHING  
            shouldOverride = true;
        }
        return shouldOverride;  
    }

    public override void OnPageStarted(global::Android.Webkit.WebView view, string url, Bitmap favicon)
    {
        view.LoadUrl(url);

    }
}`

Thanks for help.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>