I want to set listener to listen on wireless state,can anyone help me with my code
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);
//here is the event that i use that i want to listen for wifi change, and the above code is all in 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();
}
}
}
//Can anyone please help me creating a listener that will listen to the wifi state and check if wifi is connected or connecting if is not i want to enable data packet traffic through 3g/4g
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…