在选定的时间和日期设定报警 [英] set alarm on selected time and date
本文介绍了在选定的时间和日期设定报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发的Android 2.1的一个任务管理器。我想设置报警任务按日期从日期选择器,并从时间选择器设置帮助我的code ..
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
最后的EditText下一=(EditText上)findViewById(R.id.editText1);
最终巴顿分=(按钮)findViewById(R.id.button1);
最终按钮RES =(按钮)findViewById(R.id.button2);
最后的DatePicker DP =(DatePicker的)findViewById(R.id.datePicker1);
最后TimePicker TP =(TimePicker)findViewById(R.id.timePicker1);
sub.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(最终查看视图){
INT Y = dp.getYear();
INT月= dp.getMonth();
INT天= dp.getDayOfMonth();
时间t =新时代();
INT H = t.getCurrentHour();
INT M = t.getCurrentMinutes();
}
私人AlarmManager getSystemService(字符串alarmService){
// TODO自动生成方法存根
返回null;
}
});
解决方案
嘿,这就是如何在Android AlarmManager设置闹钟spesific日期 (机器人alarmmanager设定日期报警) 我一直在寻找全国各地这一点。 要注意一个月的价值!
日历CAL = Calendar.getInstance(TimeZone.getDefault(),Locale.getDefault());
//cal.add(Calendar.SECOND,10);
cal.set(Calendar.DATE,19); // 1-31
cal.set(Calendar.MONTH,Calendar.DECEMBER); //第一个月为0!一月是零!
cal.set(Calendar.YEAR,2012); //年...
cal.set(Calendar.HOUR_OF_DAY,16); //小时
cal.set(Calendar.MINUTE,39); // MIN
cal.set(Calendar.SECOND,10); //美国证券交易委员会
//创建一个新PendingIntent并把它添加到AlarmManager
意向意图=新的意图(MainActivity.this,alarmAct.class);
PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this,0,意向,0);
//或者如果你开始一个活动
// PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,意向,0);
AlarmManager AM =(AlarmManager)getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),pendingIntent);
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;
}
});
解决方案
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!!
Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
//cal.add(Calendar.SECOND, 10);
cal.set(Calendar.DATE,19); //1-31
cal.set(Calendar.MONTH,Calendar.DECEMBER); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR,2012);//year...
cal.set(Calendar.HOUR_OF_DAY, 16); //HOUR
cal.set(Calendar.MINUTE, 39); //MIN
cal.set(Calendar.SECOND, 10); //SEC
// Create a new PendingIntent and add it to the AlarmManager
Intent intent = new Intent(MainActivity.this, alarmAct.class);
PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this, 0,intent, 0);
//or if you start an Activity
//PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,intent, 0);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
这篇关于在选定的时间和日期设定报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文