Android Open Source - LearningAndroid2edYamba2 Boot Receiver






From Project

Back to project page LearningAndroid2edYamba2.

License

The source code is released under:

Apache License

If you think the Android project LearningAndroid2edYamba2 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 com.marakana.android.yamba;
//from  w  ww .  j av  a 2  s .c  om
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.Log;

public class BootReceiver extends BroadcastReceiver {
  private static final String TAG = BootReceiver.class.getSimpleName();
  private static final long DEFAULT_INTERVAL = AlarmManager.INTERVAL_FIFTEEN_MINUTES;

  @Override
  public void onReceive(Context context, Intent intent) {

    SharedPreferences prefs = PreferenceManager
        .getDefaultSharedPreferences(context);
    long interval = Long.parseLong(prefs.getString("interval",
        Long.toString(DEFAULT_INTERVAL)));

    PendingIntent operation = PendingIntent.getService(context, -1,
        new Intent(context, RefreshService.class),
        PendingIntent.FLAG_UPDATE_CURRENT);

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

    if (interval == 0) {
      alarmManager.cancel(operation);
      Log.d(TAG, "cancelling repeat operation");
    } else {
      alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
          SystemClock.elapsedRealtime(), interval, operation);
      // clk: Not using AlarmManager.RTC and corresponding System.currentTimeMillis()
      // Avoid basing your alarm on clock time if possible, if only need interval
      //  https://developer.android.com/training/scheduling/alarms.html
      Log.d(TAG, "setting repeat operation for: " + interval);
    }
    Log.d(TAG, "onReceived");
  }
}




Java Source Code List

com.marakana.android.yamba.BootReceiver.java
com.marakana.android.yamba.DbHelper.java
com.marakana.android.yamba.DetailsActivity.java
com.marakana.android.yamba.DetailsFragment.java
com.marakana.android.yamba.FreshnessView.java
com.marakana.android.yamba.MainActivity.java
com.marakana.android.yamba.NotificationReceiver.java
com.marakana.android.yamba.RefreshService.java
com.marakana.android.yamba.SettingsActivity.java
com.marakana.android.yamba.SettingsFragment.java
com.marakana.android.yamba.StatusActivity.java
com.marakana.android.yamba.StatusContract.java
com.marakana.android.yamba.StatusFragment.java
com.marakana.android.yamba.StatusProvider.java
com.marakana.android.yamba.SubActivity.java
com.marakana.android.yamba.TimelineFragment.java
com.marakana.android.yamba.YambaWidget.java