Quicky check if Data connection is available (Android SDK)

Just use the following method:

    public boolean isOnline() {
        boolean status=false;
        try{
            ConnectivityManager cm = 
                (ConnectivityManager) getActivity()
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = cm.getActiveNetworkInfo();
            status=netInfo.isConnected();
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
        return status;
    }

Posted

in

by

Tags:

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from try {} except

Subscribe now to keep reading and get access to the full archive.

Continue reading