android关于网络
16lz
2021-01-23
/** * 检测当前网络状态是否可用 * * @return */ public boolean checkNet() { ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); State mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .getState(); State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .getState(); // 移动网络 if (mobile == State.CONNECTED || mobile == State.CONNECTING) return true; // wifi网络 if (wifi == State.CONNECTED || wifi == State.CONNECTING) return true; return false; } @Override protected void onResume() { super.onResume(); // 3秒后界面消失 } /** * 网络不可用 进行网络设置 */ private void netWorkStatus() { AlertDialog.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); // 如果在设置完成后需要再次进行操作,可以重写操作代码,在这里不再重写 finish(); } }).setNeutralButton("否", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); System.exit(0); } }).show(); }
更多相关文章
- [ 转]Android 监控网络状态
- 操作Android 手机通讯录数据库
- Android:网络编程
- Android通知栏图标显示网络图片
- android 网络异步加载
- android 监听EditText 复制粘贴等操作
- Android网络电话软件Sipdroid试用