public class NetworkUtil {
public static void checkNetworkstate(final Activity activity) {
try {
//
ConnectivityManager manner=(ConnectivityManager) activity.getSystemService(activity.CONNECTIVITY_SERVICE);
NetworkInfo active=manner.getActiveNetworkInfo();
if (active==null) {
AlertDialog.Builder dialog=new AlertDialog.Builder(activity);
dialog.setMessage("没网");
dialog.setPositiveButton("打开网络", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent(Settings.ACTION_WIRELESS_SETTINGS);
activity.startActivity(intent);
}
});
dialog.setNegativeButton("取消", null);
dialog.show();
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
public static void checkNetworkstate(final Activity activity) {
try {
//
ConnectivityManager manner=(ConnectivityManager) activity.getSystemService(activity.CONNECTIVITY_SERVICE);
NetworkInfo active=manner.getActiveNetworkInfo();
if (active==null) {
AlertDialog.Builder dialog=new AlertDialog.Builder(activity);
dialog.setMessage("没网");
dialog.setPositiveButton("打开网络", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent(Settings.ACTION_WIRELESS_SETTINGS);
activity.startActivity(intent);
}
});
dialog.setNegativeButton("取消", null);
dialog.show();
}
} catch (Exception e) {
// TODO: handle exception
}
}
}