I\'m working with Android and Phonegap, and at the moment I\'m having trouble with one simple thing. I need to setup a webViewClient to the PhoneGap webView in order to capt
To accomplish what you want to do I would extend the CordovaWebViewClient class and override the methods you want but don't forget to call the super methods or PhoneGap won't work without the CordovaWebViewClient as it is an important class.
I think I've figured this out on latest Cordova versions (I'm using 2.2). It fails at onPageStarted()
because it's expecting an appView, which is null. Setting the appView seems to fix it eg
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
CordovaWebViewClient webViewClient = new CustomAcceptingWebViewClient(this);
webViewClient.setWebView(this.appView);
this.appView.setWebViewClient(webViewClient);
super.loadUrl("file:///android_asset/www/index.html");
}
Note that the super.init()
is also needed
You forgot to call super ;)
// Assign webclient.
this.appView.setWebViewClient(new CordovaWebViewClient(me, this.appView) {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
});