title: Javascript not working for WebView - Android
body: <p>Currently I have this code where I want to retrieve a content of a webview and also at the same time remove display on some part of the webview but my code didn't do anything at all or showing any error so I'm at loss here. Currently, I'm referring to <a href="https://stackoverflow.com/questions/9579772/android-get-text-out-of-webview"> this</a> and <a href="https://stackoverflow.com/questions/12257929/display-a-part-of-the-webpage-on-the-webview-android"> this</a> post for my code.</p>
  
  <p>This is the page where my webview display <a href="https://www.malaysiakini.com/news/350354" rel="nofollow noreferrer"> link</a></p>
  
  <p>This is my code 'WebViewActivity.java`</p>
  
  <pre><code>public class WebViewActivity extends Activity{
  
  TextToSpeech textToSpeech;
  
  
  @SuppressLint("JavascriptInterface")
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_webview);
  
      final WebView webview = (WebView) findViewById(R.id.webView);
      TextView contentView = (TextView) findViewById(R.id.contentView);
  
  
      Intent intent = getIntent();
      String Address = intent.getStringExtra("URL");
      //Log.d("Valuer", value);
      //tt1.setText(value);
  
      class MyJavaScriptInterface
      {
          private TextView contentView;
  
          public MyJavaScriptInterface(TextView aContentView)
          {
              contentView = aContentView;
          }
  
          @SuppressWarnings("unused")
          @SuppressLint("JavascriptInterface")
  
          public void processContent(String aContent)
          {
              final String content = aContent;
              contentView.post(new Runnable()
              {
                  public void run()
                  {
                      contentView.setText(content);
                  }
              });
          }
      }
  
      webview.getSettings().setLoadsImagesAutomatically(true);
      webview.addJavascriptInterface(new MyJavaScriptInterface(contentView), "INTERFACE");
      webview.getSettings().setJavaScriptEnabled(true);
      webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
      webview.setWebViewClient(new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url)
          {
              webview.loadUrl("javascript:window.INTERFACE.processContent(document.getElementsByClassName('western')[0].innerText);");
              webview.loadUrl("javascript:(function() { " +
                      "document.getElementsByTagName('section')[0].style.display=\"none\"; " +
                      "})()");
          }
      });
  
  
  
      webview.loadUrl(Address);
      //textToSpeech.speak("TALK", TextToSpeech.QUEUE_FLUSH, null);
  
  
  }
  
  
  
  }
  </code></pre>