2

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.

Community
  • 1
  • 1
Hao Shen
  • 2,605
  • 3
  • 37
  • 68

1 Answers1

3

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

Jackson Chengalai
  • 3,907
  • 1
  • 24
  • 39