NetworkUtil

public class NetworkUtil

Fields

ERROR_AUTH

public static final int ERROR_AUTH

ERROR_CONNECT_FAILED

public static final int ERROR_CONNECT_FAILED

ERROR_DOWNLOAD_DATA

public static final int ERROR_DOWNLOAD_DATA

ERROR_NETWORK_UNAVAILABLE

public static final int ERROR_NETWORK_UNAVAILABLE

HTTP_DELETE

public static final String HTTP_DELETE

HTTP_GET

public static final String HTTP_GET

HTTP_POST

public static final String HTTP_POST

HTTP_PUT

public static final String HTTP_PUT

TIMEOUT_CONNECTION

public static final int TIMEOUT_CONNECTION

TIMEOUT_SOCKET

public static final int TIMEOUT_SOCKET

URL_PATTERN

public static final String URL_PATTERN

mConnectionManager

protected final ConnectivityManager mConnectionManager

mContext

protected Context mContext

mLastCheckTime

protected long mLastCheckTime

mLastState

protected boolean mLastState

mTelephonyManager

protected final TelephonyManager mTelephonyManager

Constructors

NetworkUtil

public NetworkUtil(Context context)

Methods

delete

public static HttpResponse delete(String targetURL, String username, String password, boolean readErrorResponseBody)

get

public static HttpResponse get(String targetURL, String username, String password, boolean readErrorResponseBody)

getError

public static String getError(Context context, int responseCode)

getHTTPBaseAuth

public static String getHTTPBaseAuth(String username, String password)

getHttpConnection

public static HttpURLConnection getHttpConnection(String method, String targetURL, String username, String password)

getHttpResponse

protected static HttpResponse getHttpResponse(HttpURLConnection conn, boolean readErrorResponseBody)

getStream

public static void getStream(String targetURL, String username, String password, OutputStream outputStream)

isNetworkAvailable

public synchronized boolean isNetworkAvailable()

isValidUri

public static boolean isValidUri(String url)

post

public static HttpResponse post(String targetURL, String payload, String username, String password, boolean readErrorResponseBody)

postFile

public static HttpResponse postFile(String targetURL, String fileName, File file, String fileMime, String username, String password, boolean readErrorResponseBody)

put

public static HttpResponse put(String targetURL, String payload, String username, String password, boolean readErrorResponseBody)

responseToString

public static String responseToString(InputStream is)