title: How to send notification every x minutes and not send when used set sleep schedule?
body: <p>How to send notification every x minutes and not send when used set sleep schedule</p>
  <p>I am creating a reminder app to send a notification every 15,30 min when the user selects</p>
  <p>Here is my code:</p>
  <p><strong>Alarm</strong></p>
  <p>In my alarm receiver class, I check if the current time is not sleeping time shows a notification
  What is the best way to achieve this type of reminder app?</p>
  <pre><code>class AlarmReceiver : BroadcastReceiver() {
  
  private lateinit var notificationManager: NotificationManager
  private lateinit var notificationChannel: NotificationChannel
  private lateinit var builder: Notification.Builder
  val channelId = &quot;i.notification&quot;
  val description = &quot;Test notification&quot;
  
  private lateinit var builder1: NotificationCompat.Builder
  override fun onReceive(context: Context?, intent: Intent?) {
  
  
      notificationManager =
          context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
      val i = Intent(context, HomeActivity::class.java)
      intent!!.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
      val pendingIntent = PendingIntent.getActivity(context, 0, i, 0)
  
  
      val storeUserData = StoreUserData(context)
  
      val time = Date().time
      val calendar = Calendar.getInstance()
      calendar.timeInMillis = System.currentTimeMillis()
      calendar[Calendar.HOUR_OF_DAY] = storeUserData.getInt(Constants.TIMEHOURSLEEP,22)
      calendar[Calendar.MINUTE] = storeUserData.getInt(Constants.TIMEMINUTESLEEP,0)
      calendar[Calendar.SECOND] = 0
      calendar[Calendar.MILLISECOND] = 0
  
      if (time &lt;= calendar.timeInMillis) {
  
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
              notificationChannel =
                  NotificationChannel(channelId, description, NotificationManager.IMPORTANCE_HIGH)
              notificationChannel.enableLights(true)
              notificationChannel.lightColor = Color.GREEN
              notificationChannel.enableVibration(true)
              notificationChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
              notificationManager.createNotificationChannel(notificationChannel)
  
              builder = Notification.Builder(context, channelId)
                  .setSmallIcon(R.drawable.ic_splash)
                  .setContentTitle(&quot;Drink Water&quot;)
                  .setStyle(
                      Notification.BigTextStyle()
                          .bigText(
                              &quot;It's time now!&quot;
                          )
                  )
  
                  .setContentIntent(pendingIntent)
                  .setAutoCancel(true)
  
              notificationManager.notify(1234, builder.build())
  
  
          } else {
              builder1 = context.let {
                  NotificationCompat.Builder(it)
                      .setSmallIcon(R.drawable.ic_splash)
                      .setContentTitle(&quot;Drink Water&quot;)
                      .setStyle(
                          NotificationCompat.BigTextStyle()
                              .bigText(
                                  &quot;It's time now!&quot;
                              )
                      )
                      .setContentIntent(pendingIntent)
                      .setAutoCancel(true)
              }
              notificationManager.notify(1234, builder1.build())
          }
  
      }
  } }
  </code></pre>
  <p><strong>My activity</strong></p>
  <p>This is my activity where I call alarm class</p>
  <pre><code>   val pendingIntent: PendingIntent?
      val alarmIntent = Intent(this, AlarmReceiver::class.java)
      pendingIntent =
          PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)
      val manager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
      val interval = storeUserData.getInt(Constants.REMINDER_TIME,7) // 20min interval
  
  
      val time = Date().time
      val calendar = Calendar.getInstance()
      calendar.timeInMillis = System.currentTimeMillis()
      calendar[Calendar.HOUR_OF_DAY] = storeUserData.getInt(Constants.TIMEHOURWAKE)
      calendar[Calendar.MINUTE] = storeUserData.getInt(Constants.TIMEMINUTESLEEP)
      calendar[Calendar.SECOND] = 0
      calendar[Calendar.MILLISECOND] = 0
  
  
      if (time &gt; calendar.timeInMillis) {
          manager.setRepeating(
              AlarmManager.RTC_WAKEUP, time, interval * 60 * 1000L, pendingIntent
          )
      } else if (time &lt; calendar.timeInMillis) {
          manager.setRepeating(
              AlarmManager.RTC_WAKEUP, calendar.timeInMillis, interval * 60 * 1000L, pendingIntent
          )
      }
  </code></pre>
  <p>How can achieve this type of scenario,
  repeating alarm does not work properly</p>