我在Android环境中使用PhoneGap,我想知道在执行super.loadURL(myUrl)
后如何检测/捕获HTTP 404?
答案 0 :(得分:0)
您需要@Override onReceivedError
方法。
public class HelloWorld extends CordovaActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
// super.loadUrl("file:///android_asset/www/index.html");
}
/*
* (non-Javadoc)
*
* @see org.apache.cordova.CordovaActivity#onReceivedError(int,
* java.lang.String, java.lang.String)
*/
@Override
public void onReceivedError(int errorCode, String description,
String failingUrl) {
// TODO Auto-generated method stub
// super.onReceivedError(errorCode, description, failingUrl);
if (errorCode == 404) {
// show Alert here for Page Not found
Log.i("log", "Page not found 404");
} else {
Log.i("log", "Success");
}
}
}