Faisal Al-Badaai
Faisal Al-Badaai

Reputation: 13

Calling an action in certain time in android

I want to call specific action at certain time. I don't want the delay method.

let's say for example the phone will change ringer mode at 10:30 pm.

Thanks in advance and sorry for my English :)

Upvotes: 1

Views: 822

Answers (1)

Felipe FMMobile
Felipe FMMobile

Reputation: 1641

You'll have to use AlarmManager Service to do this, and a BroadcastReceiver to manage result.

AlarmManager mgr=(AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
            Intent i=new Intent(this, AlarmReceiver.class);
            PendingIntent pi=PendingIntent.getBroadcast(this, 1, i, PendingIntent.FLAG_UPDATE_CURRENT);
            mgr.cancel(pi);
            long MINUTE=AlarmManager.INTERVAL_HOUR/60;
            long TIMER=MINUTE*minutes;
            mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), TIMER , pi);

AND also

public class AlarmReceiver extends BroadcastReceiver{...

Try search for BroadCastReceiver tutorials

Upvotes: 1

Related Questions