The app I am writing involves taking details from the user and using them to access their account on a website. I know how to take details from the user but I don't know how to use those details to log into the website. Does anyone know how I can input these details in the correct boxes? Thanks in advance
4 Answers
You should use a Webview to display to webpage. Check out the official example from Google: http://developer.android.com/resources/tutorials/views/hello-webview.html
To fill the correct fields, check this answer: Fill fields in webview automatically

- 1
- 1

- 9,597
- 1
- 18
- 24
First of all, you should check out if the website has the API.
If they don't have the API,
- In Firebug (in Firefox) or Developer Tools (in Chrome), goto Network Tab and see what POST is done.
- Now that you know what is POSTed & to what URL, you have to do that using Java.
- While doing the HTTP POST/GET requests in Java, you will also need to handle cookies (which your browser does automagically for you). For that you need something called a CookieJar. You can use that without using a cookiejar too as explained here but it's cumbersome.
So, read a tutorial here & get started.

- 16,675
- 26
- 80
- 131
If the website is using POST, which is the most likely case, you can simply use UrlEncodedFormEntity and HttpClient to do that
HttpParams params = new BasicHttpParams();
HttpClient client = new DefaultHttpClient(params);
HttpPost post = new HttpPost("www.thewebsiteyouwanttosubmitto.com/post.php");
post.setEntity(new UrlEncodedFormEntity());
client.execute(post, new ResponseHandler(){});

- 1,143
- 1
- 8
- 20
Use Bookmarklets, read the source code of the login page and figure our which variables are used to Actually store the variables, for example if the 'id' for user name was 'userName' and the 'name' password was 'pwd' you could access them using
document.getElementById('userName').value
and
document.getElementsByName(\"pwd\")[0].value
if the login is a little more roundabout, like in the case of sonicwall (which i am trying to automate) these variables might be hidden, then you could use
document.standardPass.uName.value
This is some parts of the webpage for which the above codes was used,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
<form name="standardPass" onsubmit="return(processButn());" action="auth.cgi" method="POST" target="authTgtFrm">
<div id="login_box" align="left">
<div class="vgap85"></div>
<div id="error_box" style="visibility:hidden;">
<div id="error_text">
</div>
</div>
<div id="admin_reauth_text" style="visibility:hidden;">
Please enter your password to begin management:
</div>
<div id="username_line">
<div class="fieldName">
Username:
</div>
<div class="fieldValue">
<input type="text" id="userName" name="userName" value="" maxlength="32" autocomplete="off" style="width: 180px;">
</div>
</div>
<div class="vgap8"></div>
<div id="password_line">
<div class="fieldName">
Password:
</div>
<div class="fieldValue">
<input type="password" name="pwd" value="" maxlength="63" autocomplete="off" style="width: 180px;">
</div>
</div>
<div class="vgap8"></div>
<div id="language_line">
<div class="fieldName">
Language:
</div>
<div class="fieldValue">
<select name="select2">
<option>English</option>
</select>
</div>
</div>
<div class="vgap15"></div>
<div id="button_line">
<div class="fieldName">
</div>
<div class="fieldValue">
<input type="submit" name="Submit" value="Login" class="button" >
</div>
</div>
<div class="vgap8"></div>
<div id="sslvpn_enabled" style="visibility:hidden;">
<div class="fieldName">
</div>
<div class="fieldValue">
Click <a href="sslvpn" onClick="top.location.href='sslvpn'";>here</a> for sslvpn login
</div>
</div>
</div>
<input type="hidden" name="uName">
<input type="hidden" name="pass">
<input type="hidden" name="digest">
</form>
<noscript>
<center>
<font color="#FFFFFF"><font size="+1">Please turn on JavaScript to login.</font></font>
</center>
</noscript>
Now in android use webview to load the authentication page then load your bookmarklet on your webview. Test out your bookmarklet in your pc before trying in the webview. Make sure the variables are accessible in that website using your browser console(The original authentication website might be something else (Frames

- 1,024
- 11
- 10