I am creating an android app that uses the webview to open a website. My goal is for the user to never have to log back into the website once they already have. I am attempting to use POST data sent from the webview to the website with the user's username and password.
The section of html that I will be posting to is
<form action="" method="post" class="loginPad" autocomplete="off">
<h1 class="vPurple text-center loginText">
<i class="icon icon-lock vPink"></i>
Login
<span class="blink_text vPurple">>_</span>
</h1>
<div class="form-group">
<input type="text" name="username" value="" placeholder="Username" class="form-control rounded input-lg text-center no-border"
</div>
<div class="form-group">
<input type="password" name="password" value="" placeholder="Password" class="form-control rounded input-lg text-center no-border">
</div>
</form>
And then for android I have:
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
final MainActivity activity = this;
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//Users will be notified in case there's an error (i.e. no internet connection)
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
public void onPageFinished(WebView view, String url) {
CookieSyncManager.getInstance().sync();
}
});
String url = "http://www.*****.com/login.php";
String userName = "exampleUsername";
String password = "examplePassword";
String postData = "username="+userName+"& password="+password;
webView.postUrl(url, postData.getBytes());
With what I have, the webview loads the login page but doesn't do anything else.