//判断是否有网络
public class Isconnect {
//网络判断
public boolean isNet(Context context){
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo!=null&&networkInfo.isConnected()){
return true;
}
return false;
}
//若没有网络时调用该方法
public void setNet(final Context context){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("设置");
builder.setMessage("是否打开网络");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
context.startActivity(intent);
}
});
builder.show();
}
}