0
votes

Does anyone know why WebView displaying white or blank page only with my site url?

NOTE If I holding down on the white/blank page I can select "select all" and "copy". After that I paste it in a note and I can saw the content of my site. What's wrong?

My code

    var webView = new Android.Webkit.WebView(Forms.Context);

                    webView.Settings.JavaScriptEnabled = true;
                    webView.Settings.LoadsImagesAutomatically = true;
                    webView.SetWebViewClient(new MyBrowser());
                    webView.Settings.SetAppCacheMaxSize(5 * 1024 * 1024);
                    webView.Settings.SetAppCachePath(Context.CacheDir.AbsolutePath);
                    webView.Settings.AllowFileAccess = true;
                    webView.Settings.SetAppCacheEnabled(true);
                    webView.Settings.CacheMode = CacheModes.Default;
                    webView.Settings.DomStorageEnabled = true;
                    webView.PostUrl("<MyURL>", Convert.FromBase64String("<mystring>"));
                if (DetectConnection.checkInternetConnection())
                    {
                        webView.Settings.CacheMode = CacheModes.CacheElseNetwork;
                    }

                    SetNativeControl(webView);

                if (oldHWV != null)
                {

                    Control.RemoveJavascriptInterface("jsBridge");

                    oldHWV.Cleanup();

                }

                if (newHWV != null)
                {

                    Control.AddJavascriptInterface(new JSBridge(this), "jsBridge");

                    Control.LoadUrl(Element.Uri);

                    InjectJS(JavaScriptFunction);
                }
            }

            void InjectJS(string script)

            {

                if (Control != null)
                {

                    Control.LoadUrl(string.Format("javascript: {0}", script));

                }

            }

class MyBrowser : WebViewClient
    {
        override public bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, string url)
        {
                view.LoadUrl(url);
                return false;
        }

    }

Output

10-09 12:14:20.651 W/art (18729): JNI RegisterNativeMethods: attempt to register 0 native methods for md5db941dcc072fe623e29eb3b9d0ecdde3.HybridWebViewRenderer 10-09 12:14:20.732 I/WebViewFactory(18729): Loading com.android.webview version 44.0.2403.119 (code 246011900) 10-09 12:14:20.778 W/System (18729): ClassLoader referenced unknown path: /system/app/webview/lib/arm 10-09 12:14:20.796 I/LibraryLoader(18729): Time to load native libraries: 9 ms (timestamps 258-267) 10-09 12:14:20.796 I/LibraryLoader(18729): Expected native library version number "",actual native library version number "" [INFO:library_loader_hooks.cc(120)] Chromium logging enabled: level = 0, default verbosity = 0 10-09 12:14:20.823 V/WebViewChromiumFactoryProvider(18729): Binding Chromium to main looper Looper (main, tid 1) {b95d216} 10-09 12:14:20.823 I/LibraryLoader(18729): Expected native library version number "",actual native library version number "" 10-09 12:14:20.824 I/chromium(18729): [INFO:library_loader_hooks.cc(120)] Chromium logging enabled: level = 0, default verbosity = 0 10-09 12:14:20.834 I/BrowserStartupController(18729): Initializing chromium process, singleProcess=true 10-09 12:14:20.835 W/art (18729): Attempt to remove non-JNI local reference, dumping thread 10-09 12:14:20.836 E/SysUtils(18729): ApplicationContext is null in ApplicationStatus [WARNING:resource_bundle.cc(285)] locale_file_path.empty() 10-09 12:14:20.855 W/chromium(18729): [WARNING:resource_bundle.cc(285)] locale_file_path.empty() 10-09 12:14:20.864 E/libEGL (18729): validate_display:255 error 3008 (EGL_BAD_DISPLAY) 10-09 12:14:20.864 E/libEGL (18729): validate_display:255 error 3008 (EGL_BAD_DISPLAY) 10-09 12:14:20.924 E/DataReductionProxySettingListener(18729): No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp 10-09 12:14:20.968 W/art (18729): Attempt to remove non-JNI local reference, dumping thread 10-09 12:14:20.979 W/AwContents(18729): onDetachedFromWindow called when already detached. Ignoring Resolved pending breakpoint at 'HybridWebViewRenderer.cs:180,1' to void .Droid.MyBrowser.OnReceivedError (Android.Webkit.WebView view, Android.Webkit.IWebResourceRequest request, Android.Webkit.WebResourceError error) [0x00001]. 10-09 12:14:21.188 D/Mono (18729): Image addref Mono.Android.Export[0x969fcfc0] -> Mono.Android.Export.dll[0x969aa600]: 2 10-09 12:14:21.188 D/Mono
(18729): Prepared to set up assembly 'Mono.Android.Export' (Mono.Android.Export.dll) 10-09 12:14:21.188 D/Mono (18729): Assembly Mono.Android.Export[0x969fcfc0] added to domain RootDomain, ref_count=1 10-09 12:14:21.190 D/Mono (18729): AOT: image 'Mono.Android.Export.dll.so' not found: dlopen failed: library "/data/app//lib/arm/libaot-Mono.Android.Export.dll.so" not found 10-09 12:14:21.191 D/Mono (18729): AOT: image '/usr/local/lib/mono/aot-cache/arm/Mono.Android.Export.dll.so' not found: dlopen failed: library "/data/app//lib/arm/libaot-Mono.Android.Export.dll.so" not found 10-09 12:14:21.191 D/Mono (18729): Config attempting to parse: 'Mono.Android.Export.dll.config'. 10-09 12:14:21.191 D/Mono
(18729): Config attempting to parse: '/usr/local/etc/mono/assemblies/Mono.Android.Export/Mono.Android.Export.config'. 10-09 12:14:21.192 D/Mono (18729): Assembly Ref addref Mono.Android.Export[0x969fcfc0] -> mscorlib[0xa9e73f00]: 66 Loaded assembly: Mono.Android.Export.dll [External] 10-09 12:14:21.200 D/Mono (18729): Assembly Ref addref Mono.Android.Export[0x969fcfc0] -> Mono.Android[0xa8ee2d80]: 36 10-09 12:14:21.215 D/Mono (18729): Assembly Ref addref Mono.Android.Export[0x969fcfc0] -> System.Xml[0x98469fc0]: 4 Loaded assembly: callback_factory [External] 10-09 12:14:21.382 D/Mono (18729): Assembly Ref addref Mono.Android.Export[0x969fcfc0] -> System.Core[0xa8ee3680]: 8 10-09 12:14:21.389 W/art (18729): Attempt to remove non-JNI local reference, dumping thread 10-09 12:14:21.389 W/art (18729): Attempt to remove non-JNI local reference, dumping thread 10-09 12:14:21.402 D/Mono (18729): DllImport searching in: '__Internal' ('(null)'). 10-09 12:14:21.402 D/Mono (18729): Searching for 'java_interop_jnienv_call_float_method_a'. 10-09 12:14:21.402 D/Mono
(18729): Probing 'java_interop_jnienv_call_float_method_a'. 10-09 12:14:21.402 D/Mono (18729): Found as 'java_interop_jnienv_call_float_method_a'. 10-09 12:14:21.487 I/Choreographer(18729): Skipped 52 frames! The application may be doing too much work on its main thread. [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup 10-09 12:14:21.506 W/chromium(18729): [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup 10-09 12:14:21.570 W/BindingManager(18729): Cannot call determinedVisibility() - never saw a connection for the pid: 18729 10-09 12:14:21.824 W/BindingManager(18729): Cannot call determinedVisibility() - never saw a connection for the pid: 18729

Thank you in advance

1
Please check if the url is correct, and please try open your website using your test device/emulator's browser to check if it can be opened correctly. - Elvis Xia - MSFT
The url is correct and I can open it with device/emulator's browser. If I holding down on the white/blank page I can select "select all" and "copy". After that I paste it in a note and I can saw the content of my site. What's wrong? - Greta
I guess it's layout or style problem, could you please try set the webview's size to see if it fix the problem? - Elvis Xia - MSFT
I tried to modify my layout but nothing changed - Greta

1 Answers

0
votes

After different solutions on web I create a pageRenderer. I don't know if it's the best way, but it works for me. If someone has a better solution, please tell me. Thank you in advance.

[assembly: ExportRenderer(typeof(WebPage), typeof(WebPageRenderer))]
namespace <my-namespace>
{
    class WebPageRenderer : PageRenderer
    {
        global::Android.Views.View view;
        global::Android.Webkit.WebView webView;

        Activity activity;

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

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            try
            {
                Setup();
                AddView(view);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(@"ERROR: ", ex.Message);
            }
        }

        void Setup()
        {

            activity = this.Context as Activity;

            view = activity.LayoutInflater.Inflate(Resource.Layout.activity_webview, this, false);
            webView = view.FindViewById<Android.Webkit.WebView>(Resource.Id.webview);
            webView.SetWebViewClient(new WebViewClient());
            webView.Settings.JavaScriptEnabled = true;
            webView.LoadUrl("<my-url>");
        }

        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);

            var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);

            view.Measure(msw, msh);

            view.Layout(0, 0, r - l, b - t);

        }
    }

}