Android Open Source - ActivityTracker Boot Receiver






From Project

Back to project page ActivityTracker.

License

The source code is released under:

GNU General Public License

If you think the Android project ActivityTracker 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 biz.bokhorst.activitytracker;
/*from w ww . java2s  .c o m*/
/*
 Copyright 2014 Marcel Bokhorst
 All Rights Reserved

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.util.Date;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import biz.bokhorst.activitytracker.DatabaseHelper.ActivityData;

public class BootReceiver extends BroadcastReceiver {
  private static String TAG = "ATRACKER";

  @Override
  public void onReceive(final Context context, final Intent intent) {
    Log.w(TAG, "Receiver, action=" + intent.getAction());

    // Initialize service
    Intent initService = new Intent(context, BackgroundService.class);
    initService.setAction(BackgroundService.ACTION_INIT);
    context.startService(initService);

    // Check for boot completed
    if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
      // Register boot completed
      new DatabaseHelper(context).registerActivityData(new ActivityData(
          new Date().getTime(), ActivityData.TYPE_BOOT));
      Log.w(TAG, "Registered boot completed");

      // Reset step counter
      // TODO: shared preference
      SharedPreferences prefs = context.getSharedPreferences("activity",
          Context.MODE_MULTI_PROCESS);
      SharedPreferences.Editor editor = prefs.edit();
      editor.putInt("Steps", 0);
      editor.commit();
      Log.w(TAG, "Step count reset");
    }
  }
}




Java Source Code List

biz.bokhorst.activitytracker.ActivityMain.java
biz.bokhorst.activitytracker.BackgroundService.java
biz.bokhorst.activitytracker.BootReceiver.java
biz.bokhorst.activitytracker.DatabaseHelper.java
biz.bokhorst.activitytracker.GPXFileWriter.java
org.xmlrpc.android.Base64Coder.java
org.xmlrpc.android.IXMLRPCSerializer.java
org.xmlrpc.android.MethodCall.java
org.xmlrpc.android.Tag.java
org.xmlrpc.android.XMLRPCClient.java
org.xmlrpc.android.XMLRPCCommon.java
org.xmlrpc.android.XMLRPCException.java
org.xmlrpc.android.XMLRPCFault.java
org.xmlrpc.android.XMLRPCSerializable.java
org.xmlrpc.android.XMLRPCSerializer.java
org.xmlrpc.android.XMLRPCServer.java