0

I have registered a broadcastreceiver in my manifest. It is registered for

<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />

I also have registered the following permissions:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

It fires when I disable/enable wifi and when my wifi is disconnected after losing the signal (when I go away from the hotspot). But there is no broadcast when I came back to my hotspot (when wifi is connected again). I have testet it with Samsung Galaxy S5 (Android 6.0.1). Is there a peculiarity I don't know?

The code for my broadcastReceiver

public class StatusReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, Intent intent) {
        if(intent.getAction() != null)
        Log.d("action", intent.getAction());
    }
}




  <receiver android:name=".receivers.StatusReceiver">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />        
        </intent-filter>
    </receiver>

There is android.net.conn.CONNECTIVITY_CHANGE when I leave the network. And android.net.wifi.WIFI_STATE_CHANGED when I toggle the wifi button.

But no broadcast when I am returning to the hotspot or when my wifi is connected after enabling wifi

rekire
  • 47,260
  • 30
  • 167
  • 264
Ef Ge
  • 788
  • 1
  • 9
  • 26
  • can you provide broadcast receiver code – Jitesh Mohite Nov 08 '16 at 09:17
  • how you are checking that you are outside of hotspot – Jitesh Mohite Nov 08 '16 at 09:24
  • I am going away until the wifi disconnects and the mobile internet symbol appears in the status bar – Ef Ge Nov 08 '16 at 09:25
  • can you right code which check whether internet available or not on some button so that we can check whether its the problem of our program or device. http://stackoverflow.com/questions/4238921/detect-whether-there-is-an-internet-connection-available-on-android – Jitesh Mohite Nov 08 '16 at 09:27
  • I'd use [android.net.wifi.STATE_CHANGED](https://developer.android.com/reference/android/net/wifi/WifiManager.html#NETWORK_STATE_CHANGED_ACTION) instead of `` – user0815 Nov 08 '16 at 09:28
  • The code seems to be right, it fires on my other devices like charm. but not on my S5. android.net.wifi.STATE_CHANGED is also not firing – Ef Ge Nov 08 '16 at 09:34
  • I bet the problem with `CONNECTIVITY_CHANGE` is - that you're still connected - but just via mobile internet (as you said... the icon appears)... So the connected event doesn't fire when you enter the hotspot's range again. Could be wrong though :) – user0815 Nov 08 '16 at 09:49

1 Answers1

0

The smart manager (how the f... get I get rid of this?) had blocked the broadcasts to save energy. I put it to the "disabled" list and now it works like charm..

Ef Ge
  • 788
  • 1
  • 9
  • 26