我正在做这样的事情:
LoadDataWithBaseURL("file:///android_asset/adhese/",fileContent, "text/html", "UTF-8", null);
我的Webview客户类:
public class DataWebViewClient : WebViewClient
{
public delegate void PageLoaded();
public event PageLoaded PageLoadedEvent;
public AndroidAdController controller;
public override bool ShouldOverrideUrlLoading (WebView view, string url)
{
if(url.Contains ("addsResponseLoaded"))
{
view.EvaluateJavascript ("window.giveMeMyResponse();", controller.JSResultObj);
//view.StopLoading ();
return false;
}
return true;
}
public override void OnPageStarted (WebView view, string url, Android.Graphics.Bitmap favicon)
{
if (!url.Contains ("addsResponseLoaded"))
base.OnPageStarted (view, url, favicon);
else
view.StopLoading ();
}
}
javascript函数:
function giveMeMyResponse(){
// send the ads object and the response object to the native app as json
return "[{\"myAds\":"+JSON.stringify(ads)+",\"myResponse\":"+JSON.stringify(myResponse)+"}]";
}
ads.response.then(function (response) {
// send a signal to the native app the adds have succesfully loaded by changing the url to addsResponseLoaded
myAds = ads;
myResponse = response;
this.document.location.href = "addsResponseLoaded";
});
在某些设备上,例如oneplus,可以调用onpagestarted,然后调用overrideurlloading。
但是在htc或samsung galaxy等其他设备上,永远不会调用shouldoverrideurlloading方法。我应该怎么处理这个?