У меня есть это как мой webviewclient
webView = FindViewById<WebView>(Resource.Id.webView);
webView.SetWebViewClient(new WebViewClientClass());
webView.SetWebChromeClient(new WebChromeClient());
webView.ClearCache(true);
WebSettings websettings = webView.Settings;
websettings.JavaScriptEnabled = true;
websettings.DomStorageEnabled = true;
//webView.LoadUrl(ip_address + tablet_dir + "tk_tab_main.html");
webView.LoadUrl("file:///android_asset/tablet/tk_tab_main.html");
internal class WebViewClientClass : WebViewClient
{
//Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView.
public override bool ShouldOverrideUrlLoading(WebView view, string url)
{
string test = url;
if (url.EndsWith("tk_tab_work_code.html"))
{
Bitmap photo = GetQRCode("in");
using (var stream = new MemoryStream())
{
photo.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
byte[] bytes = stream.ToArray();
string base64_str = Convert.ToBase64String(bytes);
string image = "data:image/jpeg;base64," + base64_str;
string script = "javascript:SetPhoto('" + image + "');";
photo.Recycle();
view.LoadUrl(url);
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
view.EvaluateJavascript("SetPhoto('" + image + "');", null);
}
else
{
view.LoadUrl(script);
}
}
return true;
}
После загрузки URL я хочу, чтобы setphoto javascript работал со строкой изображения.Есть ли какое-то решение этого?Функция Setphoto только изменяет src изображения со строкой base64.