2

I created a Webview android app for my website so as to have an android version of my website. The website allows a user to sign in before proceeding to the website information.

Please, How do I fetch the user signed in details (e.g email) from the website in my Webview android app?

olajide
  • 972
  • 1
  • 13
  • 26
Peter Akwa
  • 77
  • 1
  • 6

1 Answers1

0

You can get the content of the WebView using this function:

yourWebView.evaluateJavascript(
        "(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
         new ValueCallback<String>() {
            @Override
            public void onReceiveValue(String html) {
                Log.d("HTML", html); 
                // Here you work with the content of the page which is stored in the 'html' variable
            }
    });

Since you are able to read the content of the page, you can either hide the data you want to read in the website in a hidden field (e.g. <input type="hidden" id="emailAddress" name="emailAddress" value="someone@example.org">).

Or you can create a own Activity where the use can insert his email address, and then you can post the inserted email address on your website using the WebView.postUrl(String url, byte[] postData) function (e.g. webView.postUrl("https://yourWebsite.com/index.php", "emailAddress=someone@example.org".getBytes());).

Source: https://developer.android.com/reference/android/webkit/WebView.html how to get html content from a webview? How to post data for WebView android

Marvin Klar
  • 1,869
  • 3
  • 14
  • 32