=====Android=====
====webviewのデバッグ====
===WebViewClient====
webViewClientのonReceivedErrorとかを使う。
[[http://developer.android.com/reference/android/webkit/WebViewClient.html| webViewClient]]
public class MainActivity extends Activity{
WebView webview = new WebView(this);
setContentView(webview);
webview.loadUrl("http://example.com/");
webview.setWebViewClient(new webViewClient(){
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
Log.e("Log", "errorCode: " + String.valueof(errorCode));
Log.e("Log", "description: " + description);
Log.e("Log", "failingUrl: " + +failingUrl);
}
});
}
}
^ErrorCode^^^
|int | ERROR_AUTHENTICATION | User authentication failed on server |
|int | ERROR_BAD_URL | Malformed URL |
|int | ERROR_CONNECT | Failed to connect to the server |
|int | ERROR_FAILED_SSL_HANDSHAKE | Failed to perform SSL handshake |
|int | ERROR_FILE | Generic file error |
|int | ERROR_FILE_NOT_FOUND | File not found |
|int | ERROR_HOST_LOOKUP | Server or proxy hostname lookup failed |
|int | ERROR_IO | Failed to read or write to the server |
|int | ERROR_PROXY_AUTHENTICATION | User authentication failed on proxy |
|int | ERROR_REDIRECT_LOOP | Too many redirects |
|int | ERROR_TIMEOUT | Connection timed out |
|int | ERROR_TOO_MANY_REQUESTS | Too many requests during this load |
|int | ERROR_UNKNOWN | Generic error |
|int | ERROR_UNSUPPORTED_AUTH_SCHEME | Unsupported authentication scheme (not basic or digest) |
|int | ERROR_UNSUPPORTED_SCHEME | Unsupported URI scheme |
===JavaScriptからコンソール出力====
JavaScriptのコンソール出力をLogcatに出す
ActivityでJavascriptを実行可に設定
WebView webview =new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
setContentView(webview);
javascript内でconsole.logを
===onConsoleMessageで出力===
端末によってはconsole.logが使えない場合があるみたいなのでこっちもあり。
[[http://developer.android.com/reference/android/webkit/WebChromeClient.html#onConsoleMessage(android.webkit.ConsoleMessage)|onConsoleMessage]]
webview.setwebChromeClient(new WebChromeClient(){
publicvoid onConsoleMessage(String message, int lineNunber, String sourceID){
Log.d("message", message);
Log.d("line", String.valueOf(lineNumber));
Log.d("URL", sourceID);
}
})