我正在使用
Android和Phonegap,目前我遇到了一个简单的问题.我需要将一个webViewClient设置到PhoneGap webView,以便捕获已完成页面的URL并使用它.
这是代码:
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); } }); }
该代码似乎不起作用,页面永远不会加载,我得到一个TIMEOUT ERROR,但如果我删除“setWebViewClient”部分页面加载完美.
我看到有一个类CordovaWebViewClient,我是否必须使用它而不是WebViewClient?我在网上找到了这种方式:
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,"onPageFinished: " + url); } @Override public void doUpdateVisitedHistory(WebView view,boolean isReload){ } });
但是那个代码也不起作用,我仍然有一个TIMEOUT ERROR.
我还看到已经有一个webVieClient成员,但如果我必须使用它以及如何使用它我不会.
我正在使用Phonegap 1.9.0版
谢谢阅读
对西蒙的回答:
这样工作,谢谢!
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,Bitmap bitmap) { super.onPageStarted(view,url,bitmap); Log.i("TEST","onPageStarted: " + url); } @Override public void onPageFinished(WebView view,String url) { super.onPageFinished(view,url); Log.i("TEST","onPageFinished: " + url); } @Override public void doUpdateVisitedHistory(WebView view,boolean isReload){ super.doUpdateVisitedHistory(view,isReload); } @Override public void onReceivedError(WebView view,int errorCode,String description,String failingUrl) { super.onReceivedError(view,errorCode,description,failingUrl); } } }