我设法让代码运行但它无法正常运行。我已经在一个确切的小时放了一个AlarmManager,显示一个文本,但问题是它出现在我按下输入按钮的那一刻,无论我介绍的是什么时候。
代码:
final TimePicker desde = (TimePicker) findViewById(R.id.timePicker1);
int desdeHora = desde.getCurrentHour();
int desdeMinuto = desde.getCurrentMinute();
Calendar desde1 = Calendar.getInstance();
desde1.set(Calendar.DAY_OF_WEEK, 3); //MIRAR ESTE 1 SIGNIFICA DOMINGO, 2 LUNES, 3 MARTES
desde1.set(Calendar.HOUR_OF_DAY,desdeHora);
desde1.set(Calendar.MINUTE,desdeMinuto);
Intent intent = new Intent(this, Alarma.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(alarmManager.RTC, (desde1.getTimeInMillis() - System.currentTimeMillis()) , 604800000, pendingIntent);
很抱歉,如果您因为我用西班牙语编程而不理解某事,请询问您是否理解不了解。
答案 0 :(得分:1)
尝试
alarmManager.setRepeating(alarmManager.RTC, (desde1.getTimeInMillis()) , 604800000, pendingIntent);
而不是
alarmManager.setRepeating(alarmManager.RTC, (desde1.getTimeInMillis() - System.currentTimeMillis()) , 604800000, pendingIntent);
顺便问一下,什么是604800000?