美文网首页
无网络连接 弹出框

无网络连接 弹出框

作者: 烟入墨 | 来源:发表于2017-07-27 14:00 被阅读0次

    //

    //获取手机连接

    ConnectivityManager manager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);

    //获取网络信息

    NetworkInfo info = manager.getActiveNetworkInfo();

    //判断

    if(info ==null){

    AlertDialog.Builder builder =newAlertDialog.Builder(MainActivity.this);

    builder.setTitle("提示?");

    builder.setMessage("是否跳转到设置");

    builder.setPositiveButton("确定",newAlertDialog.OnClickListener() {

    @Override

    public voidonClick(DialogInterface dialogInterface,inti) {

    startActivity(newIntent(android.provider.Settings.ACTION_WIFI_SETTINGS));

    }

    });

    builder.setNegativeButton("取消",null);

    AlertDialog dialog = builder.create();

    dialog.show();

    }else{

    Toast.makeText(MainActivity.this,"连接成功?",Toast.LENGTH_SHORT).show();

    }

    }

    相关文章

      网友评论

          本文标题:无网络连接 弹出框

          本文链接:https://www.haomeiwen.com/subject/zlahkxtx.html