2015-06-29 3 views
-7

Мне нужно, например, в 1:00 отправить уведомление. как я могу это сделать и периодически повторяю.Отправка уведомления в определенное время

мне нужен этот код, который будет реализован с «повтор кода»:

Intent intent = new Intent(); 

    PendingIntent pi = PendingIntent.getActivity(this, 0, intent , 0); 

    Notification notification = new NotificationCompat.Builder(this) 
      .setTicker("Ticker Title") 
      .setSmallIcon("icon") 
      .setContentTitle("Notification Content Title") 
      .setContentText("Output") 
      .setContentIntent(pi) 
      .setAutoCancel(true) 
      .build(); 

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(0, notification); 
+0

Ваш вопрос не очень описателен, но вот что вы можете сделать 1) Создать новую тему, 2) Рассчитать время в миллисекундах до времени уведомления, 3) Сон за это время, 4) Предоставить уведомление –

+2

использовать диспетчер аварий –

ответ

0
Intent myIntent = new Intent(this , NotifyService.class);  
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); 
pendingIntent = PendingIntent.getService(this, 0, myIntent, 0); 
Calendar calendar = Calendar.getInstance(); 
calendar.set(Calendar.HOUR_OF_DAY, 12); 
calendar.set(Calendar.MINUTE, 00); 
calendar.set(Calendar.SECOND, 00); 
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 12*60*60*1000 , pendingIntent); 

с помощью службы и сигнализации менеджер уведомления вы можете сделать требуемое.