Try the following:
ConnectivityManager connectivityManager = ...;
LinkProperties linkProperties = connectivityManager.getLinProperties(connectivityManager.GetActiveNetwork());
for (RouteInfo routeInfo: linkProperties.getRoutes()) {
if (routeInfo.IsDefaultRoute() && routeInfo.hasGateway()) {
return routeInfo.getGateway();
}
}