public class NetWork { //判断有无网络 public static Boolean isConn(Context context){ //得到系统服务 ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); //得到网络信息类对象 NetworkInfo info = manager.getActiveNetworkInfo(); //进行判断 if (info!=null&&info.isAvailable()){ return true; }else{ return false; } } //没网弹出一个对话框 public static void openProgressDialog(final Context context){ AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("提示"); builder.setMessage("网络出了点小差,是否设置"); builder.setPositiveButton("设置",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { //跳转到系统设置页面-隐士跳转 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); } }); builder.setNegativeButton("取消",null); builder.create().show(); }
判断有无网络
最新推荐文章于 2019-08-27 09:57:02 发布