【问题标题】:In Android, is there a way to use broadcast receiver to detect the switch between wifi and 3G?在Android中,有没有办法使用广播接收器来检测wifi和3G之间的切换?
【发布时间】:2012-04-23 04:33:32
【问题描述】:

使用广播接收器,很容易找出现在手机是否已插入。以下 StackOverflow 问题对此进行了描述: Detecting the device being plugged in.

我也知道如何使用getActiveNetworkInfo()函数来检查当前连接是WIFI还是手机,不断轮询当前连接信息。

我的问题是:是否可以使用广播接收器来检测 WiFi 和 3G 之间的切换?它应该更有效率。

【问题讨论】:

    标签: android broadcastreceiver wif 3g


    【解决方案1】:

    我认为你可以在广播接收器的 xml 文件中使用它

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

    欲了解更多信息,请查看此链接 http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 2011-03-31
      相关资源
      最近更新 更多