如何判断是否有网络
来源:互联网 发布:澳煦广告传媒php 编辑:程序博客网 时间:2024/04/30 11:07
public class Cs { public static boolean isConn(Context context){ boolean bisConnFlag=false; //1.获取网络连接的管理对象 ConnectivityManager conManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); //2.通过管理者对象拿到网络的信息 NetworkInfo network = conManager.getActiveNetworkInfo(); if(network!=null){ //3.网络状态是否可用的返回值 bisConnFlag=network.isAvailable(); } return bisConnFlag; } /** * 如果没有网络 弹出dialog对话框,,,是否进入设置网络的页面 * @param context */ public static void showNoNetWorkDlg(final Context context) { /*AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.mipmap.ic_launcher) // .setTitle("警告") // .setMessage("当前无网络,是否去设置?").setPositiveButton("设置", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 跳转到系统的网络设置界面 Intent intent = null; // 先判断当前系统版本 if(android.os.Build.VERSION.SDK_INT > 10){ // 3.0以上 intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); }else{ intent = new Intent(); intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings"); } context.startActivity(intent); } }).setNegativeButton("取消", null).show();*/ Toast.makeText(context,"没有网络,请查看网络是否正常",Toast.LENGTH_LONG).show(); }}
阅读全文
0 1
- 如何判断是否有网络
- iOS中如何判断是否有网络
- 判断是否有网络
- 判断是否有网络
- 判断是否有网络
- 判断是否有网络,是否有wifi
- android 开发中如何判断是否有网络连接
- 判断是否有可用网络
- ConnectivityManager判断是否有网络
- Android判断是否有网络
- 判断是否有网络链接
- iOS判断是否有网络
- Android 判断是否有网络
- 判断手机是否有网络
- 判断页面是否有网络
- ConnectivityManager判断是否有网络
- Android 判断是否有网络
- 封装 判断是否有网络
- POJ 2918 Tudoku 笔记
- Linux——Vim
- 二维码的生成和扫描
- RecyclerView_多条目---点击事件
- CF482B Interesting Array(线段树+位运算)
- 如何判断是否有网络
- makefile
- 第四周项目三
- POJ 3074 Sudoku 笔记
- active控件分析方法
- 第四周项目四
- Redis持久化方式RBD和AOF对比
- Mybatis使用pageHelper分页插件原理
- mslkqwmdkwwwww