I want the listener to listen to the status of the wireless network, can someone 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 case that I use so that I want to listen to the Wi-Fi change and the above code is in onCreate {}
class PhoneL extends PhoneStateListener
{
public void onWifiStateChanged(int state, String nesto)
{
mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
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 someone help me create a listener that will listen to wifi status and check if Wi-Fi is connected or connect if I do not want to enable data packet traffic via 3g / 4g
source
share