Setup Android

If you want to use http:
# settings put global captive_portal_use_https 0
# settings put global captive_portal_http_url ""
If you want to use https:
# settings put global captive_portal_use_https 1
# settings put global captive_portal_https_url ""

Maybe you have to reboot your phone after updating the settings. For more information see this.

If you are using AFWall+ you need to give access to [1000] Android-System and in some cases [10040] CaptivePortalLogin to make it work.

Setup Ubuntu

Open /etc/NetworkManager/NetworkManager.conf:
# sudo nano /etc/NetworkManager/NetworkManager.conf
Add the following lines (or change them to this):
Restart the network-manager:
# sudo service network-manager restart

For more information see this.