从Android Webview托管的网站中获取用户登录的详细信息 [英] Fetch user signed in details from a website hosted in an android Webview

查看:245
本文介绍了从Android Webview托管的网站中获取用户登录的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的网站创建了一个Webview android应用程序,以便拥有我的网站的android版本.该网站允许用户登录,然后再访问网站信息.

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.

请问,如何在Webview android应用中从网站获取用户登录的详细信息(例如电子邮件)?

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

推荐答案

您可以使用以下函数获取WebView的内容:

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
            }
    });

由于您能够阅读页面的内容,因此可以在网站的隐藏字段(例如<input type="hidden" id="emailAddress" name="emailAddress" value="someone@example.org">)中隐藏要阅读的数据.

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">).

或者您可以创建自己的Activity,用户可以在其中插入他的电子邮件地址,然后可以使用WebView.postUrl(String url, byte[] postData)功能(例如webView.postUrl("https://yourWebsite.com/index.php", "emailAddress=someone@example.org".getBytes());)将插入的电子邮件地址发布到您的网站上.

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());).

来源: https://developer.android.com/reference/android/webkit/WebView. html 如何从webview获取html内容? 如何发布WebView android的数据

这篇关于从Android Webview托管的网站中获取用户登录的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆