android 判断是否有可用网络
16lz
2021-01-23
public boolean CheckNetwork() { boolean flag = false; ConnectivityManager cwjManager = (ConnectivityManager) AndroidBaseActivity.self.getSystemService(Context.CONNECTIVITY_SERVICE); if (cwjManager.getActiveNetworkInfo() != null) flag = cwjManager.getActiveNetworkInfo().isAvailable(); if (!flag) { Builder b = new AlertDialog.Builder( AndroidBaseActivity.self).setTitle("没有可用的网络").setMessage( AndroidBaseActivity.self.getResources().getString(R.string.net_work_message)); 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"); AndroidBaseActivity.self.startActivity(mIntent); } }).setNeutralButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).create(); b.show(); } Toast.makeText(AndroidBaseActivity.self, "test", 1).show(); return flag;}
更多相关文章
- 检测Android设备有线网络连接状态
- Android 的cpu 硬盘 内存 网络设置 系统信息 硬件信息
- android检测网络连接
- android NetWorkHelper 网络工具类
- android取得当前网络连接状态
- 【Android】网络状态
- android判断是否连接网络
- Android 网络操作(上传下载等)
- 【android】监听网络变化连续多个广播的问题解决