@Override // NativeEventListener
    public void handleMessage(
        final String event, final NativeJSObject message, final EventCallback callback) {
      final Context context = GeckoAppShell.getApplicationContext();
      switch (event) {
        case "Gecko:ScheduleRun":
          if (DEBUG) {
            Log.d(
                LOGTAG,
                "Scheduling "
                    + message.getString("action")
                    + " @ "
                    + message.getInt("interval")
                    + "ms");
          }

          final Intent intent = getIntentForAction(context, message.getString("action"));
          final PendingIntent pendingIntent =
              PendingIntent.getService(
                  context, /* requestCode */ 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

          final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
          // Cancel any previous alarm and schedule a new one.
          am.setInexactRepeating(
              AlarmManager.ELAPSED_REALTIME,
              message.getInt("trigger"),
              message.getInt("interval"),
              pendingIntent);
          break;

        default:
          throw new UnsupportedOperationException(event);
      }
    }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {

    // Hotkeys
    if (keyCode == KeyEvent.KEYCODE_BACK) {

      // If the new interval != the old interval, we got to restart the
      // "alarm"
      if (originalInterval != sharedPreferences.getInt(Constants.SP_BL_INTERVAL_SERVICE, 0)) {

        // Get the interval
        int serviceInterval =
            sharedPreferences.getInt(
                    Constants.SP_BL_INTERVAL_SERVICE, (Constants.HOUR_IN_SECONDS / 2))
                * 1000;

        // Restart the AlarmManager
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        PendingIntent pendingIntent =
            PendingIntent.getService(this, 0, new Intent(this, BattlelogService.class), 0);
        alarmManager.cancel(pendingIntent);
        alarmManager.setInexactRepeating(
            AlarmManager.ELAPSED_REALTIME, 0, serviceInterval, pendingIntent);

        Log.d(
            Constants.DEBUG_TAG,
            "Setting the service to update every " + serviceInterval / 60000 + " minutes");
      }
      startActivity(new Intent(this, DashboardActivity.class));
      finish();
      return true;
    }

    return super.onKeyDown(keyCode, event);
  }
Beispiel #3
0
 public static void startServiceAlarm(Context context, Class<?> service, long interval) {
   AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
   Intent i = new Intent(context, service);
   PendingIntent p =
       PendingIntent.getService(context, REQUEST_CODE, i, PendingIntent.FLAG_CANCEL_CURRENT);
   am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, interval, p);
 }
  private void maybeSetAlarm(String action) {
    // Get alert retention settings
    int settingsLogRetentionDays =
        Integer.valueOf(prefs.getString(this.getString(R.string.pref_alert_retention_key), "30"));

    // Maybe set alarm
    if (calendar == null || action.equals("timer-changed")) {

      // Set calendar to today's date and put it ahead the appropriate number of days
      calendar = Calendar.getInstance();
      calendar.add(Calendar.DAY_OF_YEAR, settingsLogRetentionDays);

      // Create an intent to purge the database
      Intent purgeIntent = new Intent(this.getApplicationContext(), AlertLogService.class);

      // If alarm not already set or the time has changed then go for it.
      if (!isAlarmSet(purgeIntent) || action.equals("timer-changed")) {
        purgeIntent.setAction("wipe-db");
        PendingIntent pendingIntent =
            PendingIntent.getService(
                this.getApplicationContext(), 25, purgeIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        AlarmManager alarmManager =
            (AlarmManager) this.getApplicationContext().getSystemService(ALARM_SERVICE);

        alarmManager.setInexactRepeating(
            AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(),
            calendar.getTimeInMillis(),
            pendingIntent);
      }
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {

    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
      Log.d(TAG, "onReceive received ACTION_BOOT_COMPLETED");
    }

    long interval =
        Long.parseLong(
            PreferenceManager.getDefaultSharedPreferences(context).getString("interval", "900000"));
    PendingIntent operation =
        PendingIntent.getService(
            context, -1, new Intent(YambaApp.ACTION_REFRESH), PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    if (lastOp != null) alarmManager.cancel(lastOp);

    if (interval > 0) {
      // alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
      alarmManager.setInexactRepeating(
          AlarmManager.RTC, System.currentTimeMillis(), interval, operation);
      // context.startService(new Intent(context, UpdaterService.class));
    }
    lastOp = operation;

    Log.d(TAG, "onReceive interval:" + interval);
  }
  private void startLocationService() {

    mAlarm = (AlarmManager) getSystemService(ALARM_SERVICE);

    Intent i = new Intent(this, LocationPoller.class);

    i.putExtra(LocationPoller.EXTRA_INTENT, new Intent(this, LocationReceiver.class));

    i.putExtra(LocationPoller.EXTRA_PROVIDER, LocationManager.GPS_PROVIDER);

    mPendingIntent = PendingIntent.getBroadcast(this, 0, i, 0);

    mAlarm.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME_WAKEUP,
        SystemClock.elapsedRealtime(),
        PERIOD,
        mPendingIntent);

    ComponentName receiver = new ComponentName(this, BootReceiver.class);
    PackageManager pm = getPackageManager();

    pm.setComponentEnabledSetting(
        receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

    DebugMode.logger(DEBUG_TAG, "Service initialized");
  }
  /** Start/stop polling, depending on preferences. */
  public void updatePolling() {
    if (null == mStatus || !mStatus.mLinked) {
      // No polling for unlinked accounts.
      return;
    }

    Context ctx = mContext.get();
    if (null == ctx) {
      return;
    }

    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);

    // Schedule polling?
    int pos = getPrefs().getInt(Constants.PREF_POLL_INTERVAL, 0);
    if (0 == pos) {
      if (null != mPollIntent) {
        am.cancel(mPollIntent);
        mPollIntent = null;
      }
      return;
    }

    Intent poll_intent = new Intent(PollReceiver.ACTION_POLL_MESSAGES);
    mPollIntent = PendingIntent.getBroadcast(ctx, 0, poll_intent, 0);

    long interval = POLL_INTERVALS[pos - 1];
    long delay = SystemClock.elapsedRealtime() + interval;
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, delay, interval, mPollIntent);
  }
  private void registerPongListener() {
    pingID = null;

    if (pongListener != null) extXMPPConnection.removePacketListener(pongListener);

    pongListener =
        new PacketListener() {

          @Override
          public void processPacket(Packet packet) {
            if (packet == null) return;

            gotServerPong(packet.getPacketID());
          }
        };

    extXMPPConnection.addPacketListener(pongListener, new PacketTypeFilter(IQ.class));
    pingAlarmPendIntent =
        PendingIntent.getBroadcast(
            service.getApplicationContext(), 0, intentPingAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
    timeoutAlarmPendIntent =
        PendingIntent.getBroadcast(
            service.getApplicationContext(),
            0,
            intentTimeoutAlarm,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.setInexactRepeating(
        AlarmManager.RTC_WAKEUP,
        System.currentTimeMillis() + AlarmManager.INTERVAL_FIFTEEN_MINUTES,
        AlarmManager.INTERVAL_FIFTEEN_MINUTES,
        pingAlarmPendIntent);
  }
Beispiel #9
0
  static void scheduleInexactAlarm(
      Context ctxt, AlarmManager alarms, long period, boolean isDownload) {
    Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_IS_DOWNLOAD, isDownload);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);

    alarms.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, period, pi);
  }
Beispiel #10
0
 @Override
 public void onReceive(Context context, Intent intent) {
   AlarmManager alarmService = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
   Intent theIntent = new Intent(context, AttackPayload.class);
   PendingIntent pending =
       PendingIntent.getBroadcast(context, 0, theIntent, PendingIntent.FLAG_CANCEL_CURRENT);
   alarmService.setInexactRepeating(
       AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis(), SCHEDULE_TIME, pending);
 }
  private void setAlarm() {
    AlarmManager alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent uploadGesturesIntent = new Intent(UploadReceiver.UPLOAD_GESTURES);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, uploadGesturesIntent, 0);

    alarmMgr.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME, 30 * 60 * 1000, 30 * 60 * 1000, pendingIntent);

    Log.d("TouchLogger", "Start alarm clock");
  }
 public void startPeriodicUpdates() {
   if (updaterPendingIntent == null) {
     throw new Error(TAG + ": updaterPendingIntent is null");
   }
   AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
   alarmManager.setInexactRepeating(
       AlarmManager.RTC_WAKEUP,
       System.currentTimeMillis() + 15000,
       this.getUpdateInterval(),
       updaterPendingIntent);
   Log.d(TAG, "starting periodic updates now");
 }
Beispiel #13
0
  private static void setupNotificationAlarm(Context context) {
    // Create a new PendingIntent and add it to the AlarmManager
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent pendingIntent =
        PendingIntent.getBroadcast(context, 12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);

    am.setInexactRepeating(
        AlarmManager.RTC_WAKEUP,
        System.currentTimeMillis(),
        AppSettings.get().getNotificationTime(),
        pendingIntent);
  }
  @Override
  public void onCreate() {
    Log.i("ManifestCheckerService", "onCreate");
    String pathname = getCacheDir() + "/manifest.xml";
    mCacheFile = new File(pathname);

    Intent alarmIntent = new Intent(this, ManifestCheckerService.class);
    PendingIntent alarmPending = PendingIntent.getService(this, 0, alarmIntent, 0);

    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.setInexactRepeating(
        AlarmManager.RTC, System.currentTimeMillis(), AlarmManager.INTERVAL_HOUR, alarmPending);
  }
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   Log.d("test", "Srvice Start");
   Intent intent = new Intent(this, AllService.class);
   // startService(intent);
   // 以下 AlarmManagerでのserviceの再起動
   PendingIntent pendingIntent =
       PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
   AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
   // 6分ちょっとで再起動
   am.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis(), 600000, pendingIntent);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ctx = this;

    setContentView(R.layout.groups);

    SharedPreferences prefs = ctx.getSharedPreferences("Cals", 0);

    DbGroupsAdapter mDbHelper = new DbGroupsAdapter(this);
    mDbHelper.open();

    Cursor mCursor = mDbHelper.getGroups();
    ListAdapter adapter = new GroupsCursorAdapter(this, mCursor);
    setListAdapter(adapter);
    mDbHelper.close();

    Button newgroup = (Button) findViewById(R.id.newgroup);
    newgroup.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {

            DbGroupsAdapter mDbHelper = new DbGroupsAdapter(ctx);
            mDbHelper.open();
            mDbHelper.newGroup();

            Cursor mCursor = mDbHelper.getGroups();
            ListAdapter adapter = new GroupsCursorAdapter(ctx, mCursor);
            setListAdapter(adapter);
            mDbHelper.close();
          }
        });

    AlarmManager alarmManager = (AlarmManager) ctx.getSystemService("alarm");
    alarmManager.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME_WAKEUP,
        0,
        prefs.getInt("frequency", 3600000),
        PendingIntent.getBroadcast(ctx, 0, new Intent(ctx, CheckForEvents.class), 0));

    if (!prefs.getBoolean("advanced", false)) {
      Intent i = new Intent(ctx, GroupsSettings.class);
      i.putExtra("group", "1");
      startActivity(i);
      this.finish();
      // return;
    }
  }
  public static void setAlarmForWidgetUpdate(Context context, int intervalMillis) {
    // set an alarm to update the widget regularly
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, WidgetProvider.class);
    PendingIntent pendingIntent =
        PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    alarmManager.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME,
        SystemClock.elapsedRealtime(),
        intervalMillis,
        pendingIntent);

    Log.d("traces", "alarmManager created: " + intervalMillis / 60000);
  }
  public static void setServiceAlarm(Context context, boolean isOn) {

    Intent i = PollService.newIntent(context);
    PendingIntent pi = PendingIntent.getService(context, 0, i, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);

    if (isOn)
      alarmManager.setInexactRepeating(
          AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), POLL_INTERVAL, pi);
    else {
      alarmManager.cancel(pi);
      pi.cancel();
    }
    QueryPreferences.setAlarmOn(context, isOn);
  }
  public static void setAlarm(Context context, long time, boolean trigger, boolean isRom) {

    Intent i = new Intent(context, NotificationAlarm.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pi =
        PendingIntent.getBroadcast(
            context, isRom ? ROM_ALARM_ID : GAPPS_ALARM_ID, i, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pi);
    if (time > 0) {
      am.setInexactRepeating(AlarmManager.RTC_WAKEUP, trigger ? 0 : time, time, pi);
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {

      Intent alarmIntent = new Intent(context, DealDownloaderService.class);
      PendingIntent pendingIntent = PendingIntent.getService(context, 0, alarmIntent, 0);

      AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      int interval = 8000;
      manager.setInexactRepeating(
          AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);

      Log.d(TAG, getClass().getSimpleName() + " set on boot");
    }
  }
  public static void startScheduleService(Context context, long repeatTime) {

    if (DEBUG) Log.d(TAG, "HardwareButtonReceiver  startScheduleService");

    AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, StartStatusServiceReceiver.class);
    PendingIntent pending =
        PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    Calendar cal = Calendar.getInstance();

    // Start x seconds after boot completed
    cal.add(Calendar.SECOND, Config.TIME_AFTER_START);

    service.setInexactRepeating(
        AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), repeatTime, pending);
  }
  // Start the AlarmManager if it hasn't already been started.
  // The AlarmManager will take care of syncing the local database
  // in the background periodically and triggering any alarms the user has set
  public void scheduleAlarms() {
    // Sets up repeating meeting database sync
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent intent = new Intent(this, SyncReceiver.class);
    intent.setAction(SyncReceiver.SYNC);
    PendingIntent pi =
        PendingIntent.getBroadcast(
            getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, AlarmManager.INTERVAL_FIFTEEN_MINUTES, pi);

    // Reinitializes any alarms
    Intent alarmIntent = new Intent(this, SyncReceiver.class);
    alarmIntent.setAction(SyncReceiver.RESET_ALARMS);
    sendBroadcast(alarmIntent);
  }
Beispiel #23
0
  /**
   * Configura una alarma para poder realizar la sincronización en segundo plano.
   *
   * @param context Context para obtener el PreferenceManager
   */
  public static void setAlarm(Context context, AlarmManager alarmMgr, PendingIntent alarmIntent) {
    // Ponemos una alarma.
    // Se trata de poder temporizar la sincronización de la aplicación para así
    // poder enviar notificaciones al usuario.

    // Obtenemos el periodo de sincronización.
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    int syncInterval =
        1000
            * 60
            * 60
            * Integer.parseInt(
                prefs.getString(context.getString(R.string.pref_sync_frequency_key), "1"));
    alarmMgr.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME_WAKEUP, syncInterval, syncInterval, alarmIntent);
  }
Beispiel #24
0
  public static void initScheduleAlarm(Context context) {
    Log.d(TAG, "initScheduleAlarm");
    Intent intent = new Intent(context, LembramoReceiver.class);
    intent.setAction(LembramoApp.ACTION_SCHEDULE);

    final PendingIntent pendingIntent =
        PendingIntent.getBroadcast(
            context, LembramoReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    alarmManager.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME_WAKEUP,
        INTERVAL_MINUTE,
        AlarmManager.INTERVAL_DAY,
        pendingIntent);
  }
Beispiel #25
0
  public void onReceive(Context context, Intent callingIntent) {

    // Check if we should do anything at boot at all
    long interval = ((AgoraApplication) context.getApplicationContext()).getInterval();
    if (interval == AgoraApplication.INTERVAL_NEVER) return;

    // Create the pending intent
    Intent intent = new Intent(context, UpdaterService.class);
    PendingIntent pendingIntent =
        PendingIntent.getService(context, -1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Setup alarm service to wake up and start service periodically
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME, System.currentTimeMillis(), interval, pendingIntent);

    Log.d("BootReceiver", "onReceived");
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
      /* Setting the alarm here */

      Intent alarmIntent = new Intent(context, AlarmReceiver.class);

      PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);

      AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

      int interval = 8000;

      manager.setInexactRepeating(
          AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);

      Toast.makeText(context, "Alarm Set", Toast.LENGTH_SHORT).show();
    }
  }
Beispiel #27
0
 // TODO The alarm is run twice, since the circular thingie in the method...
 private void setupAlarm() {
   Intent intent = new Intent(this, Tamagotchi.class);
   br =
       new BroadcastReceiver() {
         @Override
         public void onReceive(Context c, Intent i) {
           Log.d(TAMAGOTCHI, "RUNNING ALARM");
           if (tama == null) loadTamagotchi();
           tama.Loop();
           Log.d(TAMAGOTCHI, "ALARM HAS BEEN RUN");
         }
       };
   registerReceiver(br, new IntentFilter("dk.davsebamse.tamagotchi.TamaActivity"));
   pi =
       PendingIntent.getBroadcast(
           this, 1000, new Intent("dk.davsebamse.tamagotchi.TamaActivity"), 0);
   // PendingIntent sender = PendingIntent.getBroadcast(this,0, intent, 0);
   am = (AlarmManager) getSystemService(ALARM_SERVICE);
   am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, AlarmManager.INTERVAL_HOUR, pi);
 }
Beispiel #28
0
 public static void setAlarmForPendingIntent(
     PendingIntent alarmIntent,
     AlarmManager alarmMgr,
     UpdateFrequency updateFrequency,
     TimeOfDay timeOfDayToUpdate) {
   long timeOfFirstUpdate;
   switch (updateFrequency) {
     case HOURLY:
       timeOfFirstUpdate = System.currentTimeMillis() + SHIFT;
       break;
     case DAILY:
     case WEEKLY:
       timeOfFirstUpdate = getNextUpdateTime(timeOfDayToUpdate);
       break;
     default:
       throw new IllegalStateException("Unexpected update frequency:" + updateFrequency);
   }
   alarmMgr.setInexactRepeating(
       AlarmManager.RTC, timeOfFirstUpdate, updateFrequency.getTime(), alarmIntent);
 }
Beispiel #29
0
  public static void setDailyAlarm(Context context) {

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    int hour = 0;
    long timeBeforeNext = 24 * 3600 * 1000;

    if (isPassedThresholdTime(
        PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(context.getString(R.string.key_daily_alarm_hour), 9))) {
      calendar.add(Calendar.DAY_OF_MONTH, 1);
    }
    hour =
        PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(context.getString(R.string.key_daily_alarm_hour), 9);

    //		calendar.set(Calendar.HOUR_OF_DAY, 23);
    int min =
        PreferenceManager.getDefaultSharedPreferences(context)
            .getInt(context.getString(R.string.key_daily_alarm_min), 0);

    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, min);
    calendar.set(Calendar.SECOND, 0);

    Intent myIntent =
        new Intent(context, com.cyno.reminder_premium.service.PremiumAlarmService.class);
    myIntent.putExtra(PremiumAlarmService.KEY_TIME, calendar.getTimeInMillis());
    myIntent.setAction(PremiumAlarmService.ACTION_DAILY_MORNING_ALARM);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, myIntent, 0);
    Log.d("alaarm", "from act " + String.valueOf(calendar.getTimeInMillis()));
    //		alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),timeBeforeNext
    //  , pendingIntent);  //set repeating every 24 hours
    alarmManager.setInexactRepeating(
        AlarmManager.ELAPSED_REALTIME_WAKEUP,
        calendar.getTimeInMillis(),
        AlarmManager.INTERVAL_DAY,
        pendingIntent);
  }
  @Override
  protected void onResume() {
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent i = new Intent(this.getApplicationContext(), MyService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    am.cancel(pi);
    double minutes = 1;
    // by my own convention, minutes <= 0 means notifications are disabled
    if (minutes > 0) {
      am.setInexactRepeating(
          AlarmManager.RTC_WAKEUP,
          SystemClock.elapsedRealtime() + (long) minutes * 60 * 1000,
          (long) minutes * 60 * 1000,
          pi);
    }

    Logs.d(this, "onResume");
    if (mService == null || mService.getBinder() == null) {
      doBindService();
    }

    super.onResume();
  }