在选定的时间和日期设置闹钟
我正在 Android 2.1 上开发任务管理器。我想为按日期选择器中的日期和时间选择器中的时间设置的任务设置闹钟帮助我编写代码。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText next = (EditText) findViewById(R.id.editText1);
final Button sub = (Button) findViewById(R.id.button1);
final Button res = (Button) findViewById(R.id.button2);
final DatePicker dp = (DatePicker) findViewById(R.id.datePicker1);
final TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(final View view) {
int y=dp.getYear();
int mo=dp.getMonth();
int day=dp.getDayOfMonth();
Time t = new Time();
int h=t.getCurrentHour();
int m=t.getCurrentMinutes();
}
private AlarmManager getSystemService(String alarmService) {
// TODO Auto-generated method stub
return null;
}
});
I am developing a taskmanager on Android 2.1. I want to set alarm for a task set by date from datepicker and time from time picker Help me with the code..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText next = (EditText) findViewById(R.id.editText1);
final Button sub = (Button) findViewById(R.id.button1);
final Button res = (Button) findViewById(R.id.button2);
final DatePicker dp = (DatePicker) findViewById(R.id.datePicker1);
final TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
sub.setOnClickListener(new View.OnClickListener() {
public void onClick(final View view) {
int y=dp.getYear();
int mo=dp.getMonth();
int day=dp.getDayOfMonth();
Time t = new Time();
int h=t.getCurrentHour();
int m=t.getCurrentMinutes();
}
private AlarmManager getSystemService(String alarmService) {
// TODO Auto-generated method stub
return null;
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嘿,这是如何在 android AlarmManager 上将闹钟设置为特定日期
(android Alarmmanager 在日期设置闹钟)
我一直在寻找这个。
注意这个月的价值!!
Hey this is how to set alarm on android AlarmManager to spesific date
(android alarmmanager set alarm on date)
I have been searching all over for this.
pay attention to the value of the month!!
这就是设置闹钟的方法。
日历不是必需的...但它可能会有所帮助;)
!!!请记住:当设备完全断电时,警报会取消。
http://developer.android.com/reference/android/app/AlarmManager.html
This is how to set an alarm.
Calendar isnt required... But it can be helpful ;)
!!! Remember: Alarms are canceled when the device is powered off completely.
http://developer.android.com/reference/android/app/AlarmManager.html
Android 不会为您播放闹钟,闹钟管理器允许您安排应用程序在将来的某个时间运行。
因此,只需在 AlarmManager 中添加时间和待处理意图,然后在调用该意图时播放音乐。
访问:http://developer.android.com/reference/android/app/AlarmManager .html
Android do not play alarm for you, Alarm Manager allow you to schedule your application to be run at some point in the future.
So, simply add the time and a pending intent in the AlarmManager and when this intent will be invoked, play music.
Visit: http://developer.android.com/reference/android/app/AlarmManager.html