package bwie.com.example.lenovo.zhangjun20171018;import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo;/** * Created by lenovo on 2017/10/18. */ public class NetWorkUtil {public static boolean isNetworkConnected(Context context) { if (context != null) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo != null) { return networkInfo.isAvailable(); } } return false; }public static void showNoNetWorkDlg(final Context context) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.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(); } }