Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Webview, get submitted form data

I want my Android application to use Webview to display an html form. When the user presses the Submit button, it want the name/value pairs sent back to my program. How do I do this?

I have looked at other similar questions but not of the responses tell how, specifically, to do this.

like image 234
Xarph Avatar asked Jun 01 '12 00:06

Xarph


2 Answers

Look into the use of Javascript interfaces within WebView. Please see this area of the Android Developers Guide. Basically, you should be able to communicate from the page to the device with the Javascript interface and let your WebView Activity know when the submit button is pressed and send its values over.

like image 142
Anthony Atkinson Avatar answered Nov 09 '22 20:11

Anthony Atkinson


I have found what I needed. If I set action='FORM" in the form html, then I can intercept the action with:

        public void onLoadResource (WebView view, String url){
        int index = url.indexOf("FORM?");
        if (index != -1){
            String d = URLDecoder.decode(url.substring(index+5));
        }
    }

The name/value pairs are in String d.

like image 29
Xarph Avatar answered Nov 09 '22 20:11

Xarph