0

我有这个 BroadCastReceiver 来监听WiFi状态的变化:

private BroadcastReceiver mWifiStateChangedReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {

        int extraWifiState = intent.getIntExtra(
                WifiManager.EXTRA_WIFI_STATE,
                WifiManager.WIFI_STATE_UNKNOWN
                );

        wifiState = new WifiState(Main.this);

        switch (extraWifiState) {

        case WifiManager.WIFI_STATE_DISABLED:
            wifiState.haveNetworkConnection();
            break;

        case WifiManager.WIFI_STATE_ENABLED:

            ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            while (conMan.getActiveNetworkInfo() == null
                    || conMan.getActiveNetworkInfo().getState() != NetworkInfo.State.CONNECTED) {

                wifiState.cancelDialog();

            }
            break;
        case WifiManager.WIFI_STATE_ENABLING:
            break;
        case WifiManager.WIFI_STATE_UNKNOWN:
            break;
        }
    }
};

如何在此广播接收器中添加对收听移动数据的支持?

提前谢谢各位!

4

1 回答 1

2

您可以收听"android.intent.action.ANY_DATA_STATE"并在数据连接状态更改(移动数据和/或 wifi)时收到通知。

于 2012-08-28T16:00:29.697 回答