Android Phonegap - TIMEOUT ERROR when trying to set a WebViewClient
- by Spike777
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 capture the URL of a page finished and to work with that.
This is the code:
public class PhoneGapTest extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.setBooleanProperty("loadInWebView", true);
super.clearCache();
super.keepRunning = false;
super.loadUrl("file:///android_asset/www/index.html");
super.appView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap bitmap) {
Log.i("TEST", "onPageStarted: " + url);
}
@Override
public void onPageFinished(WebView view, String url) {
Log.i("TEST", "onPageFinished: " + url);
}
});
}
That code doesn't seems to work, the page never loads and I get a TIMEOUT ERROR, but if I remove the "setWebViewClient" part the page loads perfectly.
I saw that there is a class CordovaWebViewClient, do I have to use that instead of WebViewClient? I found this way on the web:
this.appView.setWebViewClient(new CordovaWebViewClient(this){
@Override
public boolean shouldOverrideUrlLoading(final WebView view, String url) {
Log.i("BugTest", "shouldOverrideUrlLoading: " + url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap bitmap) {
Log.i("TEST", "onPageStarted: " + url);
}
@Override
public void onPageFinished(WebView view, String url) {
Log.i("TEST", "onPageFinished: " + url);
}
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){
}
});
But that code isn't working either, I still got a TIMEOUT ERROR.
I also saw that there is already a webVieClient member, but I don't if I have to use it and how.
I'm working with Phonegap version 1.9.0
Thanks for reading
Answer to Simon:
This doesn't work either, I still receive a TIMEOUT ERROR, there is something wrong?
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
super.appView.clearCache(true);
super.appView.clearHistory();
this.appView.setWebViewClient(new CustomCordovaWebViewClient(this));
super.loadUrl("file:///android_asset/www/index.html");
}
public class CustomCordovaWebViewClient extends CordovaWebViewClient {
public CustomCordovaWebViewClient(DroidGap ctx) {
super(ctx);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap bitmap) {
Log.i("TEST", "onPageStarted: " + url);
}
@Override
public void onPageFinished(WebView view, String url) {
Log.i("TEST", "onPageFinished: " + url);
}
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
}
}