Check Network and Internet Connection - Android

On comparing the accepted answer on this post to your code, what you are doing should work. Feel free to compare code. The safest thing to do would be to run a few tests from airplane mode, with the WiFi turned off, and from a location away from WiFi just to be sure. Good luck.

Android - Programmatically check internet connection and display dialog if notConnected


Have a look into one of my old answers. It has two different methods 1. to check if a device is connected to a network 2. to check if a device is connected to Internet.