Android 检测网络是否打开
Android 检测网络是否打开
1.网络是否连接(包括Wifi和移动网络)
private boolean isNetworkConnected() {
ConnectivityManager cm =
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = cm.getActiveNetworkInfo();
if (network != null) {
return network.isAvailable();
}
return false;
}
2.wifi是否可用
private boolean isWifiEnable() {
WifiManager wifiManager = (WifiManager) mContext
.getSystemService(Context.WIFI_SERVICE);
return wifiManager.isWifiEnabled();
}
3.GPS是否可用
private boolean isGpsEnable() {
LocationManager locationManager =
((LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE));
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
//Android与Internet连接的程序方式(实现HTTP连接)
1、通过java.net 中的 HttpURLConnection (自实现)
2、通过org.apach.commons.httpclient 中的 HttpClient (封装)
3、通过Android.net.http.* 中的 AndroidHttpClient(主要使用 Apache HttpClient)
4、通过com.google.Android.net.* 中的 GoogleHttpClient(主要使用 AndroidHttpClient)
更多相关文章
- [Android Pro] 创建快捷方式,删除快捷方式,查询是否存在快捷方式
- android 网络连接判断
- android连接网络
- Android: ADB网络调试
- Android 以webview的方式集成Dcloud h5+SDK
- android调用隐藏的网络信息设置菜单实现
- Android中更新UI的四种常用方式
- 移动端网络优化