In Service I want to register BroadcastReceiver for android.net.wifi.WIFI_STATE_CHANGED
public void onCreate() {
super.onCreate();
final IntentFilter filter = new IntentFilter("android.net.wifi.WIFI_STATE_CHANGED");
MyReceiver myreceiver = new MyReceiver();
// Register the receiver so that your service will listen for broadcast
registerReceiver(myreceiver , filter);
everything is good and works but after wifi state has changed for example is disconnected I want that is activated again in 5 minutes for 1 minute and then disconnected again. And after 5 minutes activated again for 1 minute. Generally connect after 5 minutes for just 1 minute and disconnect again…
I try this with AlarmManager but I am having problems how to achive that is connected after 5 minutes for 1 minute and then disconnect.
My code which is not what i try to do. It is not connected and then disconnected :
AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(this, WifiReceiver.class);
PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, alarmIntent, 0);
// start in 5 minutes and rest in 1 minutes interval
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 5*60*1000, 1*60*1000, pendingAlarmIntent);
How can i do this? I AlarmManager correct way
Use some timers to do it in your service…
SO you can determine one timer for 5 min to switch WIFI on and other for 6 min to switch off… Play with boolean dealyedAgain to make it… f.e. when first is out off 5 min change bool to true, and second will go when run ti if(..== true)