Service to keep checking WIFI to turn ON all the time on android using service -
I write a service with WifiManager class to find out if Wifi is turned off or not If my code stops, the current service is turned on, now I have used a utility which manually turns off WiFi when the service is already running. I want to see the service whether Wi-Fi is turned on or not. If this does not turn on, my code is as follows.
public int onStartCommand (intended intent, int-flags, int startId) {mainWifi = (WifiManager) getSystemService (reference.wifi_SERVICE); // Check for wifi is disabled if (mainWifi.isWifiEnabled () == incorrect) {// if wifi is disabled, enable it mainWifi.setWifiEnabled (true); } Wi = mainWifi.getConnectionInfo (); Toast. Make Text (this, "Network" + wi.getSSID (), Toast. LNNHHLLG). Show (); Return START_STICKY; }
Can anyone tell me how to do this work What I am now seeing is that which I have ever put in on the internet commencement, only once the service started But I want to run it all the time at all times and want to do some operation to broadcast later. I'm new to Android.
From time to time connection information is more convenient to register BroadcastReceiver
on android.net.wifi.WIFI_STATE_CHANGED , for example, on WIFI you can start your service from the receiver
Comments
Post a Comment