Search code examples
androidbroadcastreceiverwif3g

In Android, is there a way to use broadcast receiver to detect the switch between wifi and 3G?


Using broadcast receiver, it's easy to find out whether now the phone is plugged in or not. The following StackOverflow question describes this: Detecting the device being plugged in.

I also know how to check whether the current connection is WIFI or mobile using the function getActiveNetworkInfo() to keep polling the current connection info.

My question is: Is it possible to use the broadcast receiver to detect the switch between WiFi and 3G? It should be more efficient.


Solution

  • i think u can use this in your xml file for Broadcast receiver

     <receiver android:name="packagename.classname" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>
    

    For more clarrification check this link http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html