1

How can I get text from webview in android? Here are some of my code:

webView = (WebView)findViewById(R.id.wv_memo);
    webView.requestFocus(View.FOCUS_DOWN);
    webView.setOnTouchListener(new View.OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            switch (event.getAction())
            {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    if (!v.hasFocus())
                    {
                        v.requestFocus();
                    }
                    break;
            }
            return false;
        }
    });
    WebSettings webSettings = webView.getSettings();
    webSettings.setBuiltInZoomControls(true);
    webSettings.setJavaScriptEnabled(true);
    webView.addJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");


    webView.loadDataWithBaseURL(null,"<div contenteditable=\"true\" style=\"height:220px;\"></div>", "text/html", "utf-8", "about:blank");
Balu
  • 1,069
  • 2
  • 10
  • 24
phathsan
  • 11
  • 1
  • 3

2 Answers2

0

You should have get Html tag's value from this class

class MyJavaScriptInterface 
{

        private Context ctx;

        MyJavaScriptInterface(Context ctx) 
        {
            this.ctx = ctx;
        }

        public void showHTML(String html) 
        {
             String htmlTags = html;
        }
}

In the above code, in showHTML() method the variable htmlTags has full text of html you want.

user3264399
  • 284
  • 1
  • 13
0

None of the methods in the added interface (MyJavaScriptInterface) have been annotated with @android.webkit.JavascriptInterface; they will not be visible in API 17. WebView.addJavascriptInterface should not be called with minSdkVersion < 17 for security reasons: JavaScript can use reflection to manipulate application.

Sakthikanth
  • 139
  • 7