0

Actually I am developing an android application which starts from 4.3 and above.

In this I have functionality of getting html code for loaded webview in android 4.3 and above. whatever the code I have written is working fine for below android versions.

Here I am posting the code kindly go through it and provide your suggestion.

@SuppressLint("JavascriptInterface")

public class HTMLViewActivity extends Activity {

    private WebView web;
    @SuppressLint("JavascriptInterface")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        web = (WebView) findViewById(R.id.webView1);
        // final WebView browser = (WebView)findViewById(R.id.wv_hide);  
        web.getSettings().setJavaScriptEnabled(true);  
        web.getSettings().setLoadsImagesAutomatically(true);
        web.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");  
        web.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                web.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
            }
        });

        /* load a web page */  
        web.loadUrl("https://www.google.co.in/");  
    }

    class MyJavaScriptInterface {
        public void showHTML(String html)  
        {  
           System.out.println("html code is:::::::"+html);
        } 
    }  
}
Tasos K.
  • 7,979
  • 7
  • 39
  • 63
suraj
  • 71
  • 1
  • 1
  • 4
  • SO what is the error message that you are getting when you try to load this html page? – Eenvincible Oct 14 '14 at 15:21
  • Uncaught TypeError: Cannot call method 'processHTML' of undefined – suraj Oct 16 '14 at 14:36
  • Instead of suppressing the lints, you should have added @JavascriptInterface annotation. Also, `AddJavascriptInterface` is a lint that you *can* use, but only if your app is not open to the internet. – EpicPandaForce Mar 25 '15 at 09:58

0 Answers0