How to show message if no internet available in my android webview

alert, android, webview

Solution

Call this method before opening the `webView` if this method `returns true` that means the internet connection is avialable and you can process to the webview otherwise show some `Toast` or you can show `Dialog` if this method `returns false`.

Edit

Use this code like in your `Main Activity` as like this

if(isNetworkStatusAvialable (getApplicationContext())) {
    Toast.makeText(getApplicationContext(), "internet avialable", Toast.LENGTH_SHORT).show();
} else {
    Toast.makeText(getApplicationContext(), "internet is not avialable", Toast.LENGTH_SHORT).show();

}

Method

public static boolean isNetworkStatusAvialable (Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager != null) 
    {
        NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
        if(netInfos != null)
        if(netInfos.isConnected()) 
            return true;
    }
    return false;
}

Problem

Hi I am working with android webview application.I uses my the url succesfully in my app and it works only if internet connection available .But I want to show some messages when there is no internet connection.how can i do this ???please help me since I am new to android development and thanks :)

Original source

Related problems