开启Android程序时检测网络与GPS是否打开
2013-02-22 11:15
405 查看
很多android程序在打开时,都需要检测网络是否连接,或者GPS是否可用:
1.网络是否连接(包括Wifi和移动网络)
2.wifi是否可用
3.GPS是否可用
转自:http://blog.csdn.net/sky837/article/details/7867601
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是否可用
// Wifi是否可用 private boolean isWifiEnable() { WifiManager wifiManager = (WifiManager) mContext .getSystemService(Context.WIFI_SERVICE); return wifiManager.isWifiEnabled(); }
3.GPS是否可用
// Gps是否可用 private boolean isGpsEnable() { LocationManager locationManager = ((LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE)); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); }
转自:http://blog.csdn.net/sky837/article/details/7867601
相关文章推荐
- 开启Android程序时检测网络与GPS是否打开
- 开启Android程序时检测网络与GPS是否打开
- 开启Android程序时检测网络与GPS是否打开
- 开启Android程序时检测网络与GPS是否打开
- 开启Android程序时检测网络与GPS是否打开
- Android之检测GPS服务和定位权限是否开启
- Android判断GPS是否开启和强制帮用户打开GPS
- Android程序检测网络是否可用
- Android判断GPS是否开启和强制帮用户打开GPS
- Android程序检测网络是否可用
- Android检测网络是否可用并打开、扫描、连接WIFI
- Android程序检测网络是否可用
- Android判断GPS及网络是否开启
- Android判断GPS是否开启和强制帮用户打开GPS
- Android开发-常用工具方法(dp转成px、网络是否可用、是否3G网络、Gps是否打开、判断手机号码等)
- Android判断GPS是否开启和强制帮用户打开GPS
- Android判断GPS是否开启和强制帮用户打开GPS
- Android判断GPS是否开启和强制帮用户打开GPS
- Android下检测手机移动网络、WIFI网络是否开启或链接
- Android判断GPS是否开启和强制帮用户打开GPS