Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

we developed an app to host HTML5 applications in a WebView component. The application is developed in Xamarin, but runs only on Android.

We implemented the WeViewRenderer:

C#
public class HybridWebViewRenderer_Droid : ViewRenderer<HybridWebView, Android.Webkit.WebView>
{
   protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView> e)
   {
       base.OnElementChanged(e);

       if (Control == null)
       {
           var webView = new MyWebView(Forms.Context);
           SetNativeControl(webView);
       }

       Control.SetWebViewClient(new MyWebViewClient(this));
       Control.SetWebChromeClient(new MyWebChromeClient());
       
       Control.AddJavascriptInterface(new JSBridge(), "jsBridge");
   }
}


With a WebView like:

C#
public sealed class MyWebView : Android.Webkit.WebView
{
    private const string STR_JS_FIND_FUNCTION_FRAME_BCDRECEIVER = "javascript:if(true==Object.getOwnPropertyNames(this).toString().includes('OnBarcodeReceived')) OnBarcodeReceived('{0}'); else alert('{1}');";
    private static BarcodeReceivedHandler _barcodeReceivedEvent;

   .....
   
public MyWebView(Context context) : base(context)
     {
         Settings.JavaScriptEnabled = true;

         Settings.DomStorageEnabled = true;
         Settings.LoadWithOverviewMode = true;
         Settings.UseWideViewPort = true;
         Settings.BuiltInZoomControls = false;
         Settings.DisplayZoomControls = false;
         Settings.SetPluginState(WebSettings.PluginState.On);
         Settings.AllowContentAccess = true;

         Settings.CacheMode = CacheModes.NoCache;
         Settings.SetAppCacheEnabled(false);

         Focusable = true;
         FocusableInTouchMode = true;
         RequestFocus(FocusSearchDirection.Down);
         _barcodeReceivedEvent = ScanReceived;
     }
         .......

     private void ScanReceived(IBarcodeDataPackage bdp)
     {
         try
         {
             string para = bdp.ToJSON();
     
             string js = string.Format(STR_JS_FIND_FUNCTION_FRAME_BCDRECEIVER, para, 
                 "Diese Seite verabeitet keine Barcodes!");

             Device.BeginInvokeOnMainThread(() =>
             {
                 if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
                 {
                     EvaluateJavascript(js, null);
                 }
                 else
                 {
                     LoadUrl(js);
                 }
             });
         }
         catch(System.Exception ex)
         {
         }
     }
}


The ScanReceived method is called when an Intent is received from the BuildIn Barcode scanner (industrial device).

In the JavaScrip part of this application a method like this is implemented:

JavaScript
function OnBarcodeReceived(value){
  var bc = JSON.parse(value);
  if(null==bc){
    alert("Parameter kann nicht interpretiert werden!");
    return;
  }
  var data = bc.Data;
  
  if((null==data)||(""==data)){
    alert("Barcodestruktur ohne Daten!");
    return;
  }
  
  document.getElementById('CodeType').innerHTML = bc.BarcodeType;
  document.getElementById('ScanValue').innerHTML = data;
}


This worked fine with Chrome v70.0.3538.110 but under Crome 84.0.4147.125

the call to EvaluatJavascript or LoadUrl get run over and nothi9ng happens.

Is ther another Component that i can use, that interprets HTML5 without the System default HTML Engine?

Or can the System be configured / programmed to work with the actual version?

The HTML5 application comes from a local directory. There is no public acces or Server communication.

What I have tried:

In the productive code we use a log that shows the c# code runs as expected and without errors. Just the call to EvaluateJavascript has no longer effekt on the Javascript
Posted
Updated 1-Sep-20 4:22am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900