Rocky Pulley
Rocky Pulley

Reputation: 23321

Read fields from a WebView in an Android app

I have an android app which is native, I'm displaying a web page using JQuery Mobile inside the native app, however it has a form and I want to read the fields from my native app and use them when the user clicks submit. How can I do this? Is there an interface to read form fields on a WebView?

Upvotes: 0

Views: 1435

Answers (2)

CommonsWare
CommonsWare

Reputation: 1007359

Is there an interface to read form fields on a WebView?

Not directly. However, there is a clunky approach that you can use:

Step #1: Define a Java class that will receive data from your form, and add an instance of that class to your JavaScript environment via addJavascriptInterface(). Unfortunately, you are limited to primitives (including String) for your parameters here.

Step #2: Call loadUrl("javascript:..."), where ... is some JavaScript source code, to read the data out of your form and call the method(s) exposed on your class from step #1.

Upvotes: 1

tamsler
tamsler

Reputation: 1615

The following document should get you going.

Upvotes: 2

Related Questions