I have a service which is running on the main thread not in the background. In the service I'm checking net connection via broadcastreciver. When I enable restriction data enabled in Settings, broadcastreciver is catching intent well, but internet connection(Mobile data) is disabled to my app although it has on my device. I've seen this question, and android docs.
intentFilter.addAction("android.net.conn.ACTION_BACKGROUND_DATA_SETTING_CHANGED");
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
registerReceiver(this.connectionStatusReceiver, intentFilter);
private BroadcastReceiver connectionStatusReceiver = new BroadcastReceiver() {
@Override
public synchronized void onReceive(Context context, Intent intent) {
log.info("connection state changed");
checkConnectionState();
}
};
getActiveNetworkInfo() - *will always display CONNECTED when i switch on *restriction**
One more thing, when I switch on background data restrict, I checked intent.getAction
. It always returns android.net.conn.CONNECTIVITY_CHANGE
.
How can I check background restriction data is switched on/off?