您的位置:首页 > 理论基础 > 计算机网络

Android之检查网络是否可用(跳转网络设置页面)

2013-06-19 10:28 501 查看
private boolean NetWorkStatus() {
ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
// cwjManager.getActiveNetworkInfo();
boolean netSataus = true;
if (cwjManager.getActiveNetworkInfo() != null) {
netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
Toast.makeText(this, "网络已经打开", Toast.LENGTH_LONG).show();
} else {

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;
}


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐