开发者

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.

Than开发者_如何学Goks in advance and sorry for my English :)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜