标签:build dia star 判断网络 lis rri new 连接 sage
//判断是否有网 if (isOnline()){ btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { get(); } }); }else { nowang(); } return view; } public boolean isOnline() { //得到网络连接的管理者 这里是Fragment的情况,没有用Fragment就把getactivity()去掉 ConnectivityManager connMgr = (ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); //通过网络管理者得到网络信息 NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); //判断网络是否连接 return (networkInfo != null && networkInfo.isConnected()); } public void nowang(){ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage("要么去死,要么开网!"); builder.setNegativeButton("你敢不开网",null); builder.setPositiveButton("开网才好孩子", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //设置跳转网络界面 startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); } }); builder.create().show(); }
标签:build dia star 判断网络 lis rri new 连接 sage
原文地址:http://www.cnblogs.com/leshen/p/7401365.html