Android:闹钟每 30 分钟播放一次,从 12:30 开始 [英] Android: Alarm to be play every 30 minutes and it start from 12:30
本文介绍了Android:闹钟每 30 分钟播放一次,从 12:30 开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我将使用闹钟服务每 30 分钟播放一次闹钟.现在我已经将它设置为从 Every start 开始每 10 秒播放一次.
Here i am going to use the alarm service to play the alarm at every 30 minutes. Right now i have set it to play it at every 10 second from the Every start.
代码如下:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_layout);
Intent myIntent = new Intent(SettingsActivity.this, MyAlarmService.class);
pendingIntent = PendingIntent.getService(SettingsActivity.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 10*1000, pendingIntent);
}
现在的问题是,我想从 12:30 开始闹钟,而不是从应用程序开始的时间开始,它应该每隔 30 分钟重复播放一次.比如 1:00, 1:30, 2:00 ...等
Now the Problem is, I want to start the alarm from the 12:30 not from the time application start and it should repeatedly play at evert 30 minutes. like 1:00, 1:30, 2:00 . . . etc
那么我必须对我的代码做哪些更改?
So what changes i have to do in my code ?
推荐答案
在特定时间启动服务.看到这篇文章可能有帮助:
To start a service at specific time. see this post maybe helpful:
这篇关于Android:闹钟每 30 分钟播放一次,从 12:30 开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文