/**
     * Checks whether the device is able to connect to the network
     * @param context
     * @return
     */
    public static boolean isNetworkAvailable(Context context) {

        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity == null) {
            Log.w("tag", "couldn't get connectivity manager");

        } else {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();

            if (info != null) {

                for (int i = 0; i < info.length; i++) {

                    if (info[i].getState() == NetworkInfo.State.CONNECTED) {

                        return true;

                    }

                }

            }
        }
        return false;
    }

On Fri, Aug 21, 2009 at 3:54 AM, cafffiene <cafffi...@gmail.com> wrote:

>
> What is the simplest way to check whether my app can access the
> internet?  I am using some APIs that use the internet, but they crash
> if there is no connectivity.  So I just want to check if there is
> internet access by any means.  thanks
> >
>


-- 
Thanks and Regards
Gurudutt P.S.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to