0

如何监控活动中的网络状态?我正在使用谷歌聊天应用程序。

我只想在网络状态发生变化时执行这些行。

if(...){
    GTalkChatDetails.chat(getApplicationContext());
    GTalkChatDetails.adddMsgListener(getApplicationContext());
}
4

1 回答 1

0

创建一个类来寻找信号变化,

private class SignalStrengthListener extends PhoneStateListener 
    {
        @Override
        public void onSignalStrengthsChanged(android.telephony.SignalStrength signalStrength) 
        {
            // get the signal strength (a value between 0 and 31)
            int strengthAmplitude = signalStrength.getGsmSignalStrength();
            // do something with it
            GTalkChatDetails.chat(getApplicationContext());
                    GTalkChatDetails.adddMsgListener(getApplicationContext());
            super.onSignalStrengthsChanged(signalStrength);
        }
    }
于 2012-09-13T10:21:40.910 回答