This is sample of android native code to check internet connection
this code used for checking internet connection when you want to use network to get data from server. Before using network to get data from server, it's better to check the internet connection first. So it's a sample to do that. In this code, you can listen using broadcastlistener to check internet connection on the background when you open your app. If suddenly you lose the internet connection, app will give you notice that "no internet connection" and when you connected again with internet, app will give notice that "you are connected".
https://www.androidhive.info/2012/07/android-detect-internet-connection-status/