I am writing a test webview app, in which I intend to open my yahoo mail the moment I launch the app view. It will be a webview, where I want to hardcode my username and password. I know yahoo uses get method instead of post. Is there a way I can achieve this? Here's my code so far:
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("[email protected]", "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("[email protected]", "yahoopass");
}
}
http://developer.android.com/reference/android/webkit/WebView.html
So instead of using:
use:
You can extract the vars you need for Yahoo from the login page.