public static boolean isWIFI() { ConnectivityManager cm = (ConnectivityManager) MyApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo.getType() == ConnectivityManager.TYPE_WIFI; }
private static ConnectivityManager getConnectivityManager() { if (null == connectivityManager) { connectivityManager = (ConnectivityManager) MyApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE); } return connectivityManager; }
private static void enableHttpResponseCache() { try { long httpCacheSize = 10 * 1024 * 1024; // 10 MiB File httpCacheDir = new File(MyApplication.getInstance().getCacheDir(), "http"); Class.forName("android.net.http.HttpResponseCache") .getMethod("install", File.class, long.class) .invoke(null, httpCacheDir, httpCacheSize); } catch (Exception httpResponseCacheNotAvailable) { } }
/** * get system proxy, or null if no proxy is set. * * @return */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Proxy getProxy() { @SuppressWarnings("deprecation") String proxyName = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? Settings.Global.HTTP_PROXY : Settings.Secure.HTTP_PROXY; String proxyStr = Settings.Secure.getString(MyApplication.getInstance().getContentResolver(), proxyName); if (null == proxyStr) { return null; } String[] proxyStringSplits = proxyStr.split(":"); String proxyAddress = proxyStringSplits[0]; int proxyPort = Integer.parseInt(proxyStringSplits[1]); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyAddress, proxyPort)); }