private void sendCalendarEvents(){
  try {
    TransactionBuilder builder=performInitialized("Send upcoming events");
    BluetoothGattCharacteristic characteristic=getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
    Prefs prefs=GBApplication.getPrefs();
    int availableSlots=prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR,0);
    if (availableSlots > 0) {
      CalendarEvents upcomingEvents=new CalendarEvents();
      List<CalendarEvents.CalendarEvent> mEvents=upcomingEvents.getCalendarEventList(getContext());
      int iteration=0;
      for (      CalendarEvents.CalendarEvent mEvt : mEvents) {
        if (iteration >= availableSlots || iteration > 2) {
          break;
        }
        int slotToUse=2 - iteration;
        Calendar calendar=Calendar.getInstance();
        calendar.setTimeInMillis(mEvt.getBegin());
        Alarm alarm=GBAlarm.createSingleShot(slotToUse,false,calendar);
        queueAlarm(alarm,builder,characteristic);
        iteration++;
      }
      builder.queue(getQueue());
    }
  }
 catch (  IOException ex) {
    LOG.error("Unable to send Events to MI device",ex);
  }
}

private void sendCalendarEvents ( ) { try { TransactionBuilder builder = performInitialized ( "Send upcoming events" ) ; BluetoothGattCharacteristic characteristic = getCharacteristic ( MiBandService . UUID_CHARACTERISTIC_CONTROL_POINT ) ; Prefs prefs = GBApplication . getPrefs ( ) ; int availableSlots = prefs . getInt ( MiBandConst . PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR , 0 ) ; if ( availableSlots > 0 ) { CalendarEvents upcomingEvents = new CalendarEvents ( ) ; List < CalendarEvents . CalendarEvent > mEvents = upcomingEvents . getCalendarEventList ( getContext ( ) ) ; int iteration = 0 ; for ( CalendarEvents . CalendarEvent mEvt : mEvents ) { if ( iteration >= availableSlots || iteration > 2 ) { break ; } int slotToUse = 2 - iteration ; Calendar calendar = Calendar . getInstance ( ) ; calendar . setTimeInMillis ( mEvt . getBegin ( ) ) ; Alarm alarm = GBAlarm . createSingleShot ( slotToUse , false , calendar ) ; queueAlarm ( alarm , builder , characteristic ) ; iteration ++ ; } builder . queue ( getQueue ( ) ) ; } } catch ( IOException ex ) { LOG . error ( "Unable to send Events to MI device" , ex ) ; } }
fetch the events from the android device calendars and set the alarms on the miband .
