The task is as follows: you need to force WebView display the page after changing its content by the server. For example, when there is an expanding list on the page (implemented using js on the server side), then when you click on it, no action occurs when the list becomes active (expands) in a regular browser and we can already interact with its elements. This is necessary in order to parse the elements added to the page by the server.

WebView is invoked as follows:

 webview = new WebView(); webview.getSettings().setJavaScriptEnabled(true); webview.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT"); webview.setWebViewClient(wc); webview.setWebChromeClient(wvc); webview.loadUrl("http://klavogonki.ru/gamelist"); 

The list of games on the site is not loaded.

  • code show how to load the page in WebView - Vladyslav Matviienko

2 answers 2

I was interested in your case - really not everything is simple. Keep the working code (it is not optimal - correct it), I checked the performance on API17:

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

 WebSettings webSettings = myWebView.getSettings(); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setPluginState(WebSettings.PluginState.ON_DEMAND); webSettings.setAllowContentAccess(true); webSettings.setAppCacheEnabled(true); webSettings.setAllowContentAccess(true); webSettings.setAllowFileAccess(true); webSettings.setAllowUniversalAccessFromFileURLs(true); webSettings.setDatabaseEnabled(true); webSettings.setBlockNetworkLoads(false); webSettings.setDomStorageEnabled(true); myWebView.setWebChromeClient(new WebChromeClient()); myWebView.loadUrl("http://klavogonki.ru/gamelist"); 

In the mainifest in the application section, add android: hardwareAccelerated = "true"

Result enter image description here

  • Thank you very much, everything seems to be working. Now I can’t check everything for sure, since an attack is made on the server (someone creates a lot of clients and wants to play games, thereby overloading the server and the list is not updated, it’s possible that the Internet also has a lot). As soon as the attack stops, I check your code again and try to parse the data. In the meantime, read about the methods that you set up WebView . Very helpful. - Max.
  • Yes, it worked. - Max.

Most likely you have JS turned off in WebView (by default it is turned off). Next, I provide the code for correct display of WEB pages.

 //где myWebView - Ваша WebView final WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); //ВОТ ВКЛЮЧЕНИЕ JS!!! String userAgent = "Chrome/26.0.1410.58"; webSettings.setUserAgentString(userAgent); webSettings.setUseWideViewPort(true); webSettings.setDefaultTextEncodingName("utf-8"); webSettings.setSaveFormData(true); myWebView.loadUrl("http://mail.ru/"); 
  • Did not work. I, of course, have this feature enabled, because I am using js get data from the server. I will add to the question how I call the WebView . - Max.