Retrieving Text Data from Android Webview

Asked 2 years ago, Updated 2 years ago, 118 views

I am viewing the text data sent in the server method in the Android web view.
How do I retrieve this data from the webview by textual data?I tried the code below, but the value is null.

public class MainActivity extensions AppCompatActivity{

    private Timer mainTimer;
    private MainTimerTask mainTimerTask;
    private int count = 0;
    private handler mHandler=newHandler();
    private TextView the label;



    //
    private Timer mainTimer2;
    private MainTimerTask mainTimerTask2;
    private int count2 = 0;
    private handler mHandler2 = newHandler();

    @ Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_main);


        WebView myWebView= (WebView) findViewById (R.id.webView);

        myWebView.setWebViewClient(newWebViewClient());

        myWebView.loadUrl("http://192.168.43.238/"; // http://192.168.43.238/
        WebSettings webSettings=myWebView.getSettings();
        webSettings.setDefaultFontSize(60);



        myWebView.scrollTo(0, myWebView.getContentHeight());


        count=myWebView.getContentHeight();


        This.mainTimer=newTimer();

        This.mainTimerTask = newMainTimerTask();

        This.mainTimer.schedule(mainTimerTask, 1000, 100);




        myWebView.evaluateJavascript(
                "(function() {return( document.getElement.inertext);})();",
                newValueCallback<String>(){
                    @ Override
                    public void onReceiveValue(Stringhtml){
                        Log.d("HTML", html);
                        // code here
                    }
                });


    }


    public class MainTimerTask extensions TimerTask {
        @ Override
        public void run() {

            mHandler.post(new Runnable(){
                public void run() {

                    WebView myWebView= (WebView) findViewById (R.id.webView);

                    count+=1000;

                    myWebView.scrollTo(0, count); // getContentHeight();

                    WebSettings webSettings=myWebView.getSettings();
                    webSettings.setDefaultFontSize(60);



                    myWebView.evaluateJavascript(
                            "(function() {return( document.getElement.inertext);})();",
                            newValueCallback<String>(){
                                @ Override
                                public void onReceiveValue(Stringhtml){
                                    Log.d("HTML", html);
                                    // code here
                                }
                            });
                }

            });
        }
    }
}

javascript android arduino

2022-09-30 17:05

1 Answers

document.getElement.innerText does not appear to be working properly

When javascript retrieves a specific element, it is done like document.getElementById("id"), so isn't it javascript("(function(){return(document.getElement.inertext);});" error?

I think it would be better to open the web page you are trying to open from the PC's Chrome and run javascript from the console to see if the results come back as expected.
↓Wouldn't it be better to refer to these things?
http://www.buildinsider.net/web/chromedevtools/01#page-9


2022-09-30 17:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.