Saturday, January 2, 2016

Prevent webview from showing "web page not available"

Apply the below Code,

WebView.setWebViewClient(new WebViewClient() {
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        WebView.loadUrl("file:///android_asset/myerrorpage.html");

    }
});

Saturday, September 12, 2015

Android Internet Connection checking

private boolean isNetworkConnected() 
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null) 
{
       //There are no active networks.       return false;
} 
else
{
        return true;
}
}


The above function will return true only if the device has internet connection otherwise false.

manifest file permissions,
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Wednesday, July 9, 2014

WebView Unicode Support

mWebView.loadDataWithBaseURL(null, "தமிழில் கணினி", "text/html", "utf-8", null);
OR
WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");

Tuesday, July 8, 2014

Load Image from URL

Use the following code to display the picture in ImageView,
URL url = new URL("http://www.vijaynetwork.com/vijay_top_logo.jpg");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);

Wednesday, June 4, 2014

How to open a new layout after button click in android

Use the below code,

How to write static HTML code in WebView control

Apply the below code,

webView = (WebView) findViewById(R.id.webView1);
webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setBuiltInZoomControls(true);
webViewSettings.setPluginState(PluginState.ON);
webView.getSettings().setJavaScriptEnabled(true);
String data="<h1>welcome to Android example..Write your own HTML code here..</h1><br>";
webView.loadData(data, "text/html","utf-8");

Thursday, May 29, 2014

How to enable Java Script in WebView

       myWebView = (WebView) findViewById(R.id.WebView1);
       WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);