0

I am working on the option menu to click on the menu item so I can fetch the html source as a string. I want to fetch the html source from the webview, but i dont know how to do this.

Here is the code:

    webView.getSettings().setJavaScriptEnabled(true);

    // For API level below 18 (This method was deprecated in API level 18)
    webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    if (Build.VERSION.SDK_INT >= 19) {
        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    else {
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    webView.loadUrl("file:///android_asset/richtexteditor/index.html");

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == R.id.action_send) {
        }
    }

Can you please show me an example how I can fetch the html source from the webview when I click on the option menu item?

chris oojer
  • 301
  • 1
  • 10
  • Why do you want the HTML from the webview? You can make a client request from Android code to the same URL and get the HTML response. https://developer.android.com/reference/java/net/HttpURLConnection – PeterMmm Jul 22 '22 at 20:30
  • I want to get the HTML from the webview, because i want to fetch the HTML string to post the data. I am using `file:///android_asset/richtexteditor/index.html` which is store on the location app. I cant use html response because it will show empty data when I input the information in the rich text editor. Any idea?? – chris oojer Jul 22 '22 at 20:34
  • Sorry, I do not get you. `to post the data`, where, when ? Probably you should explain more what is index.html. – PeterMmm Jul 22 '22 at 20:42
  • Sorry, What I mean is when I write the texts in the rich text editor of the webview, I want to fetch the HTML source code so I can send the email. The index.html is the rich text editor file. – chris oojer Jul 22 '22 at 20:44
  • I did a quick google search and it say that I need to use `executeJavascript` but not sure if it will work? – chris oojer Jul 22 '22 at 20:48
  • So, try it. https://stackoverflow.com/questions/63170016/get-value-from-input-in-android-webview – PeterMmm Jul 22 '22 at 20:51
  • I dont know what you expect me to look for? – chris oojer Jul 22 '22 at 20:57
  • Even if you get the source, it wouldn't include the contents of an editor on the page. That's not how forms work. – Gabe Sechan Jul 22 '22 at 21:30
  • Oh right, what do I need to use then to get the contents of an editor on the page? I have been told to use webview. I have tried to use edittext, it is easy but it will not support the images when I select them on my phone. – chris oojer Jul 22 '22 at 21:59
  • Gabe Sechan Do you know how I can fetch the html from the rich text view on the webview? – chris oojer Jul 23 '22 at 15:33

0 Answers0