android 检测网络是否连接
2012-10-18 16:38
537 查看
1.首先得将下面的权限添加到AndroidManifest.xml中
2.核心代码实现:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2.核心代码实现:
package com.hui.network; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class CheckNetwork { public boolean check(Context context) { //取得ConnectivityManager ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); if (info == null || !connectivityManager.getBackgroundDataSetting()) { return false; } //获得网络类型 int type = info.getType(); //取得链接的详细信息 int subType = info.getSubtype(); if (type == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (type == ConnectivityManager.TYPE_MOBILE) { return info.isConnected(); } else { return false; } } }
相关文章推荐
- android的网络是否连接状态检测及具体连接的网络类型
- android 检测网络是否连接,或者GPS是否可用
- Android 检测设备是否连接网络
- Android检测手机是否有网络连接可用
- Android 检测网络是否连接
- Android中如何简单检测网络是否连接
- Android开发检测网络是否连接
- Android检测网络是否可用并打开、扫描、连接WIFI
- android检测网络是否连接,WIFI是否连接
- Android检测手机是否有网络连接可用
- Android 检测网络连接是否可用
- 交叉编译ifplugd中的ifplugstatus(检测网线或无线网络是否连接上)
- 检测网络连接是否正常的方法
- Android检测网络状态,判断当前网络是否可用
- Android 判断是否有网络连接
- android判断网络是否连接
- Android开发--判断网络是否连接
- [Android实例] android 检测网络是否存在 [复制链接]
- Android 检测网络连接状态
- Androidの网络Http之判断是否连接服务器