Package com.zendesk.sdk.util
Class NetworkUtils
- java.lang.Object
-
- com.zendesk.sdk.util.NetworkUtils
-
public class NetworkUtils extends java.lang.ObjectThis class is a collection of utility methods for determining network state.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static NetworkInfogetActiveNetworkInfo(Context context)Gets the currently activeNetworkInfo.static ConnectivityManagergetConnectivityManager(Context context)Obtains an instance of theConnectivityManagerstatic booleanisConnected(Context context)Determines whether we have a usable connection or not.static booleanisMobile(Context context)Determines whether we are on a mobile network or not.
-
-
-
Method Detail
-
isConnected
public static boolean isConnected(Context context)
Determines whether we have a usable connection or not.Specifically this calls
NetworkInfo#isConnected()which determines that a usable connection is present.- Parameters:
context- The context which will be used to obtain an instance ofConnectivityManager- Returns:
- true if a usable connection is present, false otherwise.
-
isMobile
public static boolean isMobile(Context context)
Determines whether we are on a mobile network or not.This checks if the type of the current active network is
ConnectivityManager#TYPE_MOBILE, as reported byNetworkInfo#getType()- Parameters:
context- The context which will be used to obtain an instance ofConnectivityManager- Returns:
- true if the current active connection is a mobile one, false otherwise.
-
getConnectivityManager
public static ConnectivityManager getConnectivityManager(Context context)
Obtains an instance of theConnectivityManagerThis is simply a convenience method for obtaining a
ConnectivityManagerwithout having to callContext#getSystemService(String)- Parameters:
context- The context which will be used to obtain an instance ofConnectivityManager- Returns:
- An instance of
ConnectivityManageror null if it was not found.
-
getActiveNetworkInfo
public static NetworkInfo getActiveNetworkInfo(Context context)
Gets the currently activeNetworkInfo.Please note that your application must have the
Manifest.permission#ACCESS_NETWORK_STATEpermission in order for this method to return actual data.- Parameters:
context- The context which will be used to obtain an instance ofNetworkInfo- Returns:
- The
NetworkInforepresenting the active network connection or null if there was an issue looking this up.
-
-