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

更多相关文章

  1. Android(安卓)内存管理工具
  2. Android主流网络请求框架Volley
  3. Android(安卓)5.0WebView选择本地文件
  4. android Intent Flags详解
  5. Android(安卓)如何设置网关和路由
  6. LinearLayout布局中将一个控件放在屏幕的最下方-Android
  7. Android(安卓)网络与数据存储
  8. Android(安卓)网络视频播放
  9. Android视频录制

随机推荐

  1. Android中可自由移动悬浮窗口的实现
  2. Android使用Fragment,不能得到Fragment内
  3. Android(安卓)XML小工具
  4. android将老项目改为按屏幕大小自适应,只
  5. 14天学会安卓开发(第十一天)Android图形
  6. android Application Component研究之Act
  7. 安卓003快速入门
  8. 一个最简单的基于Android(安卓)SearchVie
  9. activity的四个启动模式
  10. Android核心分析(26)-----Android(安卓)GDI