android - 在Android中,有没有办法使用广播接收器来检测wifi和3G之间的切换?

标签 android broadcastreceiver wif 3g

使用广播接收器,可以很容易地知道现在手机是否已插入。以下 StackOverflow 问题描述了这一点: Detecting the device being plugged in .

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

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

最佳答案

我认为你可以在广播接收器的 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

关于android - 在Android中,有没有办法使用广播接收器来检测wifi和3G之间的切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10274818/

相关文章:

android - 无法在 SD 卡上写入文件

android - 不兼容的类型 : String cannot be converted to OnInitializationCompleteListener

android - 当 minifyEnabled=true 时 GMail API 无法正常工作

android - 如何重绘surfaceview android的一部分

机器人 : ACTION_PACKAGE_ADDED not received (xperia SO-03D)

c# - 无法解析/使用 System.ServiceModel.Security.WSTrustServiceContract 作为服务名称

asp.net - 限制 ADFS 2.0 使用特定 OU 而不是域级别访问

web-services - 处理 SAML 断言是如何工作的?

Android Broadcastreceiver 在 list 中注册时需要取消注册吗?

android - AlarmManager.RTC_WAKEUP 在关闭时不会唤醒我的 Android 设备