Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m using android webview to show url.but when there is no internet connection it shows whole url
Like:abc.com not available. I want that url does not show when no internet
Posted

1 solution

Hello,

You can use following function to check whether internet connection is available or not.
Java
private boolean isNetAvailable() {
    ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = conMgr.getActiveNetworkInfo();
    if (null == netInfo)
    {
        // There are no active networks.
        return false;
    }
    else
       return true;
 }

You will also require to add following entry in manifest file.
XML
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Regards,
 
Share this answer
 
Comments
garav kumar mishra 25-Apr-13 11:22am    
Thanks for reply but. What issue is that:.
Suppose i have called google via web view and then i search for toy or etc and then wifi/internet gets disconnected then it shows url there

How to handle this
Prasad Khandekar 25-Apr-13 11:43am    
Hello Gaurav,

You can use above mentioned function along with DefaultHttpClient to check whether the URL is accessible or not. if it's accessible then do not show the WebView.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900