Code example for WebView

Methods: getSettingsloadDataWithBaseURL

0
	 
	@Override	 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 
		WebView webview = new WebView(this);
		setContentView(webview);
 
		// get app version 
		String version;
		try 
		{ 
			version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;			
		} 
		catch(NameNotFoundException e)
		{ 
			version = "unknown";			
		} 
		 
		StringBuilder total = new StringBuilder();
		try 
		{ 
			String filename = ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) ? "about.html" : "about_phone.html";
			BufferedReader r = new BufferedReader(new InputStreamReader(getAssets().open("about_page/" + filename)));
			String line;
			while ((line = r.readLine()) != null) {
			    total.append(line);
			}			 
		} 
		catch(IOException e)
		{			 
		} 
		 
		// append FreeRDP core version to app version 
		version = version + " (" + LibFreeRDP.getVersion() + ")";
		 
		String about_html = "no about ;(";
		try 
		{ 
			about_html = String.format(total.toString(), version, Build.VERSION.RELEASE ,Build.MODEL);
		} 
		catch(IllegalFormatException e)
		{ 
			about_html="Nothing here ;(";
		} 
		webview.getSettings().setJavaScriptEnabled(true);
		webview.loadDataWithBaseURL("file:///android_asset/about_page/", about_html, "text/html", null, "about:blank");
	} 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE