我想设置监听器来监听无线状态,谁能帮我写代码
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
...
TelephonyManager wTelephonyManager;
...
wTelephonyManager=(TelephonyManager)getSystemService(Context.WIFI_SERVICE);
wTelephonyManager.listen(new PhoneL(),PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
//这里是我要监听wifi变化的事件,上面的代码都在onCreate{}
class PhoneL extends PhoneStateListener
{
public void onWifiStateChanged(int state, String nesto)
{
mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
//mWifi.isConnectedOrConnecting()
if(mWifi.isConnectedOrConnecting())
{
Toast.makeText(WifiActivity.this,"Ima WIFI",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(WifiActivity.this,"! NEMA WIFI",Toast.LENGTH_LONG).show();
}
}
}
//谁能帮我创建一个监听器,它将监听wifi状态并检查wifi是否连接或连接是否我想通过3g / 4g启用数据包流量