android 检查网络是否连接了
[下载]php java javascript 相关 api 手册的下载
代码如下
/**
*
* @param activity
* @return boolean return true if the application can access the internet
*/
public static boolean hasInternet(Activity activity) {
ConnectivityManager manager = (ConnectivityManager) activity
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.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;
}
需要在AndroidManifest.xml中 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
增加权限:
[本日志由 80x86 于 2009-11-30 05:28 PM 编辑]
Tags:
Tags: 评论: 0 | 引用: 0 | 查看次数: 329
发表评论
你没有权限发表评论!请先注册再评论:点击注册
上一篇
下一篇