阅读更多

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)

更多相关文章

  1. Android关闭其他程序
  2. android 获取 imei号码
  3. Android下为自己定义WifiManager类wifi模块代码
  4. android连接网络
  5. android 网络连接判断
  6. Android(安卓)Studio中断开SVN连接
  7. Android中如何判断是否联网
  8. Android(安卓)检测网络是否打开
  9. Android检测网络连接

随机推荐

  1. android 支持的Html标签
  2. Android(安卓)代码提示无效
  3. Android(安卓)Studio下,gradle project sy
  4. Android(安卓)开发中,px、dip、density 间
  5. Android(安卓)SDK镜像的介绍使用
  6. Android(安卓)adb shell 报错:more than o
  7. Android(安卓)去掉Power键按钮 锁屏界面
  8. android 怎么把网络图片生成一个Bitmap显
  9. android ListView增加Animation效果
  10. Android学习笔记:RecyclerView