2015-11-07 74 views
0

我有报警和通知,他们都工作正常,但我需要触发哪些用户和天,这是恒定的输入在特定时间报警:触发在指定的日期和时间报警

1.tonight在timepicker时间 2.tomorrow在 3.3天后来在 4.14天后来在 5.30天后来在 6.90天后来在timepicker时间

这里timepicker时间timepicker时间timepicker时间timepicker时间是我的代码:

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
      TimePicker timePicker1; 
      timePicker1 = (TimePicker) findViewById(R.id.timePicker1); 
      // ---get current date and time--- 
      Calendar calendar = Calendar.getInstance(); 


      // ---PendingIntent to launch activity when the alarm 
      // triggers--- 
      Intent intent = new Intent(List2.this, 
        DisplayNotifications.class); 
      intent.putExtra("message", esmdars); 
      intent.putExtra("Title", "alarm"); 
      PendingIntent pendingIntent = PendingIntent.getBroadcast(
        List2.this, 0, intent, 0); 

      // ---sets the alarm to trigger--- 

      alarmManager.set(
        AlarmManager.RTC_WAKEUP, 
        System.currentTimeMillis() 
          + (TimeUnit.SECONDS.toMillis(30)), 
        pendingIntent); 

报警本节触发并显示例如通知这里30秒后启动:

alarmManager.set(
        AlarmManager.RTC_WAKEUP, 
        System.currentTimeMillis() 
          + (TimeUnit.SECONDS.toMillis(30)), 
        pendingIntent); 

我怎样才能在天,在这一天中的特定时间被激活?

回答

0

试试这个:

Calendar calendar = Calendar.getInstance(); 
calendar.setTimeInMillis(System.currentTimeMillis()); 
calendar.set(Calendar.HOUR_OF_DAY, hour); 
calendar.set(Calendar.MINUTE, minutes); 
calendar.set(Calendar.DAY_OF_MONTH, day_of_month); 
calendar.set(Calendar.MONTH, month); 
calendar.set(Calendar.YEAR, year); 
alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); 
+0

,我怎么拨打了报警到2天响的例子吗?在分拣机时间? –

+0

day_of_year = calendar.get(Calendar.DAY_OF_YEAR)+ 2; calendar.set(Calendar.DAY_OF_YEAR,day_of_year); – Szamot