我正在编写一个测试 webview 应用程序,我打算在启动应用程序视图的那一刻打开我的雅虎邮件。这将是一个网络视图,我想在其中硬编码我的用户名和密码。我知道雅虎使用 get 方法而不是 post。有没有办法可以做到这一点?到目前为止,这是我的代码:
Webview webview = (WebView) getView().findViewById(R.id.mywebview);
webview.setBackgroundColor(0);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new webClient());
String url = "https://www.yahoomail.com";
webview.loadUrl(url);
private class webClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
view.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
final Animation fade = new AlphaAnimation(0.0f, 1.0f);
fade.setDuration(200);
view.startAnimation(fade);
view.setVisibility(View.VISIBLE);
}
public void animate(final WebView view) {
final Animation anim = AnimationUtils.loadAnimation(getActivity(),
R.anim.slide_in_from_left);
view.startAnimation(anim);
}
@Override
public void onReceivedError( WebView view, int errorCode, String description, String failingUrl ) {
Toast.makeText(view.getContext(), "Authentication Error", Toast.LENGTH_LONG).show();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setCookie("yahooemail@yahoo.com", "yahoopass");
super.onReceivedError(view, errorCode, description, failingUrl);
}
@Override
public void onLoadResource( WebView view, String url ){
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onReceivedHttpAuthRequest( WebView view, final HttpAuthHandler handler, final String host, final String realm ){
handler.proceed("yahooemail@yahoo.com", "yahoopass");
}
}