Code example for WebView: Displaying web pages

Methods: addJavascriptInterfaceclearCachegetSettingsloadUrlsetWebChromeClientsetWebViewClient

0
        Log.d("sysout","thread-->" + Thread.currentThread().getId());
        Log.d("sysout","activity-->" + Thread.currentThread().getName());
        setContentView(R.layout.webview_layout);
 
      webview = (WebView) this.findViewById(R.id.mywebview);
       webview.getSettings().setJavaScriptEnabled(true);
       webview.getSettings().setBuiltInZoomControls(true);
       webview.addJavascriptInterface(this, "nativeApp");
       final Activity activity = this;
       
       webview.setWebChromeClient(new WebChromeClient() {
         public void onProgressChanged(WebView view, int progress) {
           // Activities and WebViews measure progress with different scales. 
           // The progress meter will automatically disappear when we reach 100% 
           activity.setProgress(progress * 1000);
         } 
       }); 
        
 
        
       webview.setWebViewClient(new WebViewClient() {
         public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
           Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_LONG).show();
         } 
 
		@Override 
		public void onPageFinished(WebView view, String url) {
			// TODO Auto-generated method stub 
//			webview.loadUrl("javascript:document.all.aftertest.style.color = 'red'"); 
//			webview.loadUrl("javascript:window.webdriver.showToast('<head>'+document.getElementById(\"txtMultiLine1\").value+'</head>');"); 
//			webview.loadUrl("javascript:window.webdriver.resultAvailable('<head>'+document+'</head>');"); 
//			String string = interface1.getResult(); 
//			Log.d("Mywebview", "yes:" + string); 
//			String script = Uri.encode("<script>var d=document.getElementById(\"link_id\");d.innerHTML;</script>"); 
//			String script = "<script>var d=document.getElementById(\"link_id\");d.innerHTML;</script>" ; 
//			 webview.loadUrl("javascript:function b(){var a=document.getElementById('link_id');return a.innerHTML};");			 
//			 webview.loadUrl("javascript:window.nativeApp.back(b())"); 
		} 
        
		@Override 
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			// TODO Auto-generated method stub 
			return super.shouldOverrideUrlLoading(view, url);
		} 
          
       }); 
 
        
//       webview.loadUrl("file:///sdcard/android_webview_html/item_detail-0db2-null.jhtml.htm"); 
//       webview.loadUrl("file:///sdcard/android_webview_html/textfields1.html"); 
       webview.loadUrl("file:///sdcard/android_webview_html/link1.html");
       webview.clearCache(true);
       
//       webview.set 
//       JavascriptExecutor executor = new JavascriptExecutor(); 
//       final JavascriptInterface interface1 = new JavascriptInterface(this,executor); 
// 
Connect your IDE to all the code out there  Get Codota for Java