标签:android style blog color os io ar div cti
if (isConnect(this)==false) { new AlertDialog.Builder(this) .setTitle("网络错误") .setMessage("网络连接失败,请确认网络连接") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub android.os.Process.killProcess(android.os.Process.myPid()); System.exit(0); } }).show(); } public static boolean isConnect(Context context) { // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理) try { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { // 获取网络连接管理的对象 NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null&& info.isConnected()) { // 判断当前网络是否已经连接 if (info.getState() == NetworkInfo.State.CONNECTED) { return true; } } } } catch (Exception e) { // TODO: handle exception Log.v("error",e.toString()); } return false; }
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
标签:android style blog color os io ar div cti
原文地址:http://www.cnblogs.com/a354823200/p/3931592.html