Android Open Source - Points Daily Alarm Starter






From Project

Back to project page Points.

License

The source code is released under:

GNU General Public License

If you think the Android project Points listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package se.frusunnanbo.points;
/*w  w w . j  a  v a  2 s  .  com*/
import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class DailyAlarmStarter extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent arg1) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      Intent intent = new Intent(context, DailyPointsActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      
      PendingIntent operation = PendingIntent.getActivity(context, 0, intent, 0);
      Calendar whenToStart = Calendar.getInstance();
      
      whenToStart.set(Calendar.HOUR_OF_DAY, 20);
      whenToStart.set(Calendar.MINUTE, 30);
      whenToStart.set(Calendar.SECOND, 0);
      
      long whenToStartAbsolute = whenToStart.getTimeInMillis();
      long currentTime = System.currentTimeMillis();
      long diff = 0;
      
      if (currentTime < whenToStartAbsolute) {
        diff = whenToStartAbsolute - currentTime;
      }
      else {
        diff = currentTime - whenToStartAbsolute;
      }      
      
      alarmManager.setInexactRepeating(AlarmManager.RTC, diff, AlarmManager.INTERVAL_DAY, operation);      
      
  }

}




Java Source Code List

se.frusunnanbo.points.Constants.java
se.frusunnanbo.points.DailyAlarmStarter.java
se.frusunnanbo.points.DailyPointsActivity.java
se.frusunnanbo.points.Prefs.java
se.frusunnanbo.points.SettingsActivity.java
se.frusunnanbo.points.Storage.java