android - 连接管理器 - android.net.conn.CONNECTIVITY_CHANGE

标签 android android-intent

我为 android.net.conn.CONNECTIVITY_CHANGE 创建了一个过滤器.
我确实收到了我的广播接收器的 Intent 。

我的问题是关于引发 connectivity_change 的原因。 API 描述说:

A change in network connectivity has occurred. A connection has either been established or lost. The NetworkInfo for the affected network is sent as an extra; it should be consulted to see what kind of connectivity event occurred.

我的 broadcastreceiver 似乎只在移动网络连接/断开时被调用(pdp 坏了)。它不会在例如 2g 切换到 3g 时引发。

我不能用这个广播接收器捕获 2g 到 3g 的交换吗?
我是否必须使用 phonestatelistener 来捕捉从 2g 到 3g 的交换?

最佳答案

你需要:

permission "android.permission.READ_PHONE_STATE"//获取连接变化(2G/3G/等) permission "android.permission.ACCESS_COARSE_LOCATION"//获取 Cell/Tower 更改

//Make the listener
listener = new PhoneStateListener() { 
    public void onDataConnectionStateChanged(int state, int networkType) 
    { 
       //We have changed proticols, for example we have gone from HSDPA to GPRS
       //HSDPA is an example of a 3G connection 
       //GPRS is an example of a 2G connection
    }
    public void onCellLocationChanged(CellLocation location) {
       //We have changed to a different Tower/Cell
    }
};

//Add the listener made above into the telephonyManager
telephonyManager.listen(listener, 
        PhoneStateListener.LISTEN_DATA_CONNECTION_STATE //connection changes 2G/3G/etc
        | PhoneStateListener.LISTEN_CELL_LOCATION       //or tower/cell changes 
); 

关于android - 连接管理器 - android.net.conn.CONNECTIVITY_CHANGE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8127324/

相关文章:

android - 低功耗蓝牙加密和数据安全

java - 无法解决 Android Studio 中的符号 'menu' 错误

Android Spinner 值和文本

android - 无法在 Eclipse IDE 上获取项目的系统库

html - 使用 Android Intent 发送 HTML 邮件

android - 从浏览器拦截链接以打开我的 Android 应用程序

Android - JSON mySQL 查询给出 NetworkOnMainThreadException

android - 与来自服务的 Activity (LocalService) 进行通信 - Android 最佳实践

android - 当 Activity 销毁时再次调用 onStart 的服务

java - Android Wear 消息监听器