zoukankan      html  css  js  c++  java
  • android 检测网络是否连接,或者GPS是否可用

    很多android程序在打开时,检测网络是否连接,或者GPS是否可用:

    1.网络是否连接(包括Wifi和移动网络)

    1. // 是否有可用网络  
    2.     private boolean isNetworkConnected() {  
    3.         ConnectivityManager cm =   
    4.                 (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);  
    5.         NetworkInfo network = cm.getActiveNetworkInfo();  
    6.         if (network != null) {  
    7.             return network.isAvailable();  
    8.         }  
    9.         return false;  
    10.     }  

    2.wifi是否可用

    1. // Wifi是否可用  
    2.     private boolean isWifiEnable() {  
    3.         WifiManager wifiManager = (WifiManager) mContext  
    4.                 .getSystemService(Context.WIFI_SERVICE);  
    5.         return wifiManager.isWifiEnabled();  
    6.     }  

    3.GPS是否可用

      1. // Gps是否可用  
      2.     private boolean isGpsEnable() {  
      3.         LocationManager locationManager =   
      4.                 ((LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE));  
      5.         return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);  
      6.     }  

    参考:http://blog.csdn.net/sky837/article/details/7867601

  • 相关阅读:
    叶树:任总喊你回家吃饭 (zz)
    一个小员工如何让一家大银行一夕倒闭(附几则)
    精妙SQL语句收集
    降温了 降温了
    東京タワー初めてphoto
    圣诞气氛photo
    初冬071110photo
    超级郁闷的一天
    eveningplan
    KOF怀念ING
  • 原文地址:https://www.cnblogs.com/lh92lxm/p/3431009.html
Copyright © 2011-2022 走看看