Package com.zendesk.sdk.util
Class NetworkUtils
- java.lang.Object
-
- com.zendesk.sdk.util.NetworkUtils
-
public class NetworkUtils extends java.lang.Object
This 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 NetworkInfo
getActiveNetworkInfo(Context context)
Gets the currently activeNetworkInfo
.static ConnectivityManager
getConnectivityManager(Context context)
Obtains an instance of theConnectivityManager
static boolean
isConnected(Context context)
Determines whether we have a usable connection or not.static boolean
isMobile(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 theConnectivityManager
This is simply a convenience method for obtaining a
ConnectivityManager
without having to callContext#getSystemService(String)
- Parameters:
context
- The context which will be used to obtain an instance ofConnectivityManager
- Returns:
- An instance of
ConnectivityManager
or 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_STATE
permission in order for this method to return actual data.- Parameters:
context
- The context which will be used to obtain an instance ofNetworkInfo
- Returns:
- The
NetworkInfo
representing the active network connection or null if there was an issue looking this up.
-
-