Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check Network Availability on android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 353
    Comment on it

    We know that Its not possible that our android device should be always connected with a network.
    It might be a situation when we would not connected with any network, So to check it whether we are connected with any network or not.

    We check it by using ConnectivityManager class and get network information by NetworkInfo.
    We need to add this permission in manifest file : ACCESS_NETWORK_STATE

    Here if nInfo returns null that means there is no network. And that is not null then we just check the connectivity.
    This is the simple code/method for it.

    public boolean isConnection(){
    ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nInfo = connectivityManager.getActivityNetworkInfo();
    If(nInfo !=null && nInfo.isConnected()){
    return true;
    }
    return false;
    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: