让我们一起爱米兰
站内搜搜:
移动设备
请扫描二维码
或访问
m.milan100.com
您所在的位置 -> 米兰百分百 -> android相关 -> android判断是否联网

android判断是否联网

点击数:1125 发表时间:2010-11-25 08:12:48 作者: 来源链接:
分享到:
分享到微信

首先在AndroidManifest.xml 里增加检查网络状态的权限
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

 

/*
*@return
boolean return true if the application can access the internet
*/
private boolean haveInternet(){
NetworkInfo info=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE).getActiveNetworkInfo();
if(info==null || !info.isConnected()){
return false;
}
if(info.isRoaming()){
//here is the roaming option you can change it if you want to disable internet while roaming, just return false
return true;
}
return true;
}

0
很 好
0
一 般
0
差 劲
热门新闻
相关文章
上一篇: android扫描无线网络
下一篇: adb工具的使用
评论区
匿名

返回首页 | 收藏本页 | 回到顶部
Copyright 2010. 米兰百分百 Powered By Bridge.
京ICP备15050557号