My app is a kiosk mode app (unless the user enters a code, he won't be able to access any Android apps). So, when the tab boots up, there are some settings to be done in a service. I am using the below code to check for network connectivity (this code is being reused as its part of utility class in my work). If there is network available, I need to execute a command, else an event has to be triggered.
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
In Android 7, this code works flawlessly. On boot up, since there is a SIM and network connectivity is available, I can execute the command.
But in Android 6, even when there is network availability, the code always returns not connected/OFFLINE. This happens on the device boot up. But, the connectivity returns true after the app launches.
Internally, the connectivityManager.activeNetworkInfo is based on a BroadcastReceiver with IntentFilter ConnectivityManager.CONNECTIVITY_ACTION. From the logs, I can see that the CONNECTIVITY_ACTION is being registered during the app installation, but this doesn't happen on device boot up.
I tried to make network connectivity check on the class which extends Application but that also is not working - thinking that check will make the app aware at start up that there is a network connection.