Android 9 API 28 ONLY WebView is showing a black pop up in some devices

夙愿已清 提交于 2019-12-11 07:46:38

问题


I have been trying to figure out why one of the pop-ups inside a webview is showing a black screen in some devices. please see attach The URL works as URI but not inside the webview.

note: it seems the url have javascript issues. not sure why android 9 block its content

[chromium] [INFO:CONSOLE(3)] "Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/5093566007214080", source: https://mylink.com/js/libs/jquery/jquery.min.js (3)

Edit: I use a render to being able to get current location

xaml :

 <local:GeoWebView x:Name="Webview" HorizontalOptions="FillAndExpand"  
    VerticalOptions="FillAndExpand" />

c#

Webview.Source = new UrlWebViewSource
            {
               Url=https://MyLink.com/thisismytesturl.htm
            };

Render Android :

public class GeoWebViewRenderer : WebViewRenderer
    {
        public GeoWebViewRenderer(Context context) : base(context)
        {
        }

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

            Control.Settings.JavaScriptEnabled = true;
            Control.Settings.DomStorageEnabled=true;
          Control.Settings.JavaScriptCanOpenWindowsAutomatically=true;
            Control.SetWebChromeClient(new MyWebClient());
        }
    }

    public class MyWebClient : WebChromeClient
    {
        public override void OnGeolocationPermissionsShowPrompt(string 
         origin, GeolocationPermissions.ICallback callback)
        {
            callback.Invoke(origin, true, false);
        }
    }

2.it suppose to show something similar to the image.


回答1:


Follow the steps mentioned below:

  1. Editing useCleartextTraffic attribute in manifest file.

  2. Adding Network Security Config.

    <application
        android:usesCleartextTraffic="true">
    
    <base-config cleartextTrafficPermitted="true">
         <trust-anchors>
             <certificates src="system" />
             <certificates src="user" />
         </trust-anchors>
     </base-config>
    


来源:https://stackoverflow.com/questions/56634016/android-9-api-28-only-webview-is-showing-a-black-pop-up-in-some-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!