Code example for WebView: Displaying web pages

Methods: getSettingsloadUrlsetWebChromeClientsetWebViewClient, setDownloadListener

0
 
		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		setContentView(R.layout.main);
		myweb = (WebView) findViewById(R.id.WebView);
 
		myweb.setWebViewClient(new HelloWebViewClient());
 
		myweb.setWebChromeClient(new WebChromeClient() {
			@Override 
			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 * 100);
			} 
 
		}); 
		myweb.setDownloadListener(new DownloadListener() {
	        /* (non-Javadoc) 
	         * @see android.webkit.DownloadListener#onDownloadStart(java.lang.String, java.lang.String, java.lang.String, java.lang.String, long) 
	         */ 
	        public void onDownloadStart(String url, String userAgent,
	                String contentDisposition, String mimetype,
	                long contentLength) {
	            Intent intent = new Intent(Intent.ACTION_VIEW);
	            intent.setData(Uri.parse(url));
	            startActivity(intent);
 
	        } 
	    }); 
		Toast.makeText(this, "Please wait",
				Toast.LENGTH_LONG).show();
 
		myweb.loadUrl("file:///android_asset/index.html");
 
		myweb.getSettings().setJavaScriptEnabled(true);
 
		myweb.getSettings().setPluginsEnabled(true);
		myweb.getSettings().setBuiltInZoomControls(true);
 
		SharedPreferences settings = getSharedPreferences("MyPrefsFile", 0);
		isfirsttime = settings.getBoolean("isfirsttime", false);
		if (isfirsttime) {
			SharedPreferences.Editor editor = settings.edit();
Stop searching for code, let great code find you!  Add Codota to your java IDE