判断网络状态
2015-11-23 15:11
330 查看
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
private boolean getNetWorkStatus() {
boolean netSataus = false;
ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
cwjManager.getActiveNetworkInfo();
if (cwjManager.getActiveNetworkInfo() != null) {
netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
}
if (!netSataus) {
Builder b = new AlertDialog.Builder(this).setTitle("没有可用的网络")
.setMessage("是否对网络进行设置?");
b.setPositiveButton("是", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Intent mIntent = new Intent("/");
ComponentName comp = new ComponentName(
"com.android.settings",
"com.android.settings.WirelessSettings");
mIntent.setComponent(comp);
mIntent.setAction("android.intent.action.VIEW");
startActivityForResult(mIntent,0);
}
}).setNeutralButton("否", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
}).show();
}
return netSataus;
}
android:name="android.permission.ACCESS_NETWORK_STATE" />
private boolean getNetWorkStatus() {
boolean netSataus = false;
ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
cwjManager.getActiveNetworkInfo();
if (cwjManager.getActiveNetworkInfo() != null) {
netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
}
if (!netSataus) {
Builder b = new AlertDialog.Builder(this).setTitle("没有可用的网络")
.setMessage("是否对网络进行设置?");
b.setPositiveButton("是", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Intent mIntent = new Intent("/");
ComponentName comp = new ComponentName(
"com.android.settings",
"com.android.settings.WirelessSettings");
mIntent.setComponent(comp);
mIntent.setAction("android.intent.action.VIEW");
startActivityForResult(mIntent,0);
}
}).setNeutralButton("否", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
}).show();
}
return netSataus;
}
相关文章推荐
- 协议森林08 不放弃 (TCP协议与流通信)
- 三种嵌入式web服务器(Boa / lighttpd / shttpd)的 linux移植笔记 2
- 网络请求Http
- [python&php 网络编程]把socket改成阻塞或非阻塞模式
- 简单的scala实现的网络爬虫
- LeNet -5 卷积神经网络的网络结构
- RMI、Hessian、Burlap、Httpinvoker、WebService的比较
- AFNetWorking初探之AFHTTPRequestOperation(三)
- setsockopt()改善socket网络程序的健壮性
- 揭开Socket编程的面纱http://www.cnblogs.com/goodcandle/archive/2005/12/10/socket.html
- Java - 网络编程(NetWork)
- iOS9 beta 请求出现App Transport Security has blocked a cleartext HTTP (http://)
- 是什么原因导致 无法连接到远程服务器
- Oracle ORA-24247: 网络访问被访问控制列表 (ACL) 拒绝
- iOS 使用模拟器的时候快速切换网络的指令
- TCP协议与流通信
- Linux tcpdump命令详解
- Linux网络编程socket错误分析
- linux下性能测试工具: http_load、
- linux 网络编程 inet_pton & inet_ntop函数