Skip to content

Instantly share code, notes, and snippets.

Created January 23, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/30f18702e450f0cdf0fe to your computer and use it in GitHub Desktop.
Save anonymous/30f18702e450f0cdf0fe to your computer and use it in GitHub Desktop.
Android WebView
Button button = (Button) findViewById(R.id.button);
Toolbar toolbar = (Toolbar) findViewById(R.id.myToolbar);
final WebView webView = (WebView) findViewById(R.id.webView);
//Set links to show in webview not open in another program.
webView.setWebViewClient(new WebViewClient());
Log.d(this.toString(), "Getting settings.");
webView.getSettings().setJavaScriptEnabled(true);
String url = "http://alexhedley.com/protirus/form.asp";
webView.loadUrl(url);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
String barcode = "barcode";
String fillIn = "document.getElementById('barcode').value = '" + barcode + "';";
String click = "(function(){document.getElementById('btnEnter').click();})()";
String combined = "javascript:" + fillIn + click;
webView.loadUrl(combined);
}
};
button.setOnClickListener(listener);
<android.support.v7.widget.Toolbar
android:id="@+id/myToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<form method="POST" action="form-process.asp">
<label for="barcode">Barcode: </label>
<input id="barcode" name="barcode" type="text" value="">
<br />
<input id="btnEnter" name="btnEnter" type="submit" value="Submit">
</form>
<uses-permission
android:name="android.permission.INTERNET">
</uses-permission>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment