I am developing an app to be used on a specific tablet running Android 7.0. I'm using a Service
to send periodic DatagramPacket
s. I can only use mobile networks. I check the connectivity status using ConnectivityManager
, NetworkInfo
and DetailedState
. I get the network state with this code:
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
DetailedState networkState = activeNetwork.getDetailedState();
- If the tablet is plugged in and the screen is on or off, I get CONNECTED state.
- If the tabled is unplugged and the screen is on, I get CONNECTED state.
- If the tabled is unplugged and the screen is off, I get BLOCKED state.
In my tablet the Data Saver is off. Just in case, I have run tests to verify there are no restrictions when the screen turns off, cm.getRestrictBackgroundStatus()
always returns 1, which is RESTRICT_BACKGROUND_STATUS_DISABLED, even when the network is blocked.
So, why is the network blocked? Do my app need special permissions? Do my tablet need special configuration?