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" />

更多相关文章

  1. Android Q 版本新的网络状况判断方式
  2. Android SQLite数据操作 【学习记录】
  3. android 中判断有无网络连接
  4. Android 网络超时
  5. 【Android网络编程】获取网络图片,具有缓存功能
  6. [Android] Android打开WIFI或者移动网络
  7. Android中重写onBackPressed()方法实现双击退出
  8. android操作ini工具类
  9. Android判断网络状态

随机推荐

  1. 使用android上传文件
  2. Eclipse 安装 Google Android(安卓)插件
  3. Android的多媒体框架OpenCore(PacketVideo
  4. Android(安卓)NDK环境搭建
  5. Android(安卓)Input子系统浅谈
  6. WebView In Mobile App
  7. 将Android(安卓)DHCPInfo 属性转换为int
  8. Android开发资源完全汇总
  9. Ubuntu下搭建Android(安卓)NDK开发环境
  10. android设置按钮背景透明度与设置布局背