0

I have to monitor the connectivity of the device automatically, to do that I have my receiver registered with

<receiver android:name=".NetworkStateReceiver" android:exported="true">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            <action android:name="android.net.wifi.STATE_CHANGE"/>
            <action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
        </intent-filter>
</receiver>

It works fine, but when the WiFi goes to sleep mode, the network info will have the state DISCONNECTED/BLOCKED. This is ok, I understand why it does this to save battery etc.

The issue is that the receiver doesn't receive an intent when the WiFi goes to sleep mode. Same thing if I wake up the device, the WiFi will switch to connected state but I won't receive an intent.

(Tested on a Nexus 5X)

Any way I could receive those events without having to use an alarm that would fire every X minutes to check the state?

Checked Connectivity Change Broadcast receiver not triggering when phone is in sleep mode but answer seems irrelevant

Community
  • 1
  • 1
badoualy
  • 386
  • 2
  • 10
  • which targetSdkVersion are you using? – Lebedevsd Jan 02 '17 at 09:15
  • min version is 10, target will be the latest. My nexus has latest version, I managed to get the events by listening to the android.os.action.DEVICE_IDLE_MODE_CHANGED intent. I'll test to check whether the behavior is the same on pre M devices – badoualy Jan 02 '17 at 09:18
  • The thing is that since M version you are not receiving wifi events while your application is not on foreground – Lebedevsd Jan 02 '17 at 09:21
  • check out this http://stackoverflow.com/questions/32151603/scan-results-available-action-return-empty-list-in-android-6-0 – Lebedevsd Jan 02 '17 at 09:24
  • ?? Where is this coming from? My broadcast does receive the intent when the app is in the background (al registered in manifest) – badoualy Jan 02 '17 at 09:26

0 Answers0