Created
July 20, 2019 15:14
-
-
Save manarFci/2b77804615d8173d35656c8c8126be7e to your computer and use it in GitHub Desktop.
check Network connectivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.quakereport; | |
import android.content.Context; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
/** | |
* Created by macbook on 7/20/19. | |
*/ | |
public class NetworkHelper { | |
public static boolean hasNetworkAccess(Context context){ | |
ConnectivityManager cm = | |
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
try { | |
NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); | |
boolean isConnected = activeNetwork != null && | |
activeNetwork.isConnectedOrConnecting(); | |
return isConnected; | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment