Android Open Source - activity-tracker Activity Recognition Service






From Project

Back to project page activity-tracker.

License

The source code is released under:

MIT License

If you think the Android project activity-tracker 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 org.hopto.mjancola.service;
/*  w  w w .j  a  v a 2 s  .c om*/
import android.app.IntentService;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity;

public class ActivityRecognitionService extends IntentService
{
    public static final String ACTIVITY_DETECTED = "ARS-motion-detected";
    public static final String MOTION_EVENT      = "ARS-motion-type";

    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public ActivityRecognitionService( String name )
    {
        super( name );
    }

    public ActivityRecognitionService()
    {
        super( "ActivityRecognitionService" );
    }

    @Override
    protected void onHandleIntent(Intent intent)
    {
        if ( ActivityRecognitionResult.hasResult( intent ))
        {
            ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
            // Put your application specific logic here (i.e. result.getMostProbableActivity())
            Log.e( "*****", "Got result: " + result.getMostProbableActivity().toString() );

            // broadcast the change
            broadCastMotion(result.getMostProbableActivity());
        }
    }

    private void broadCastMotion(DetectedActivity motion)
    {
        Intent intent = new Intent(ActivityRecognitionService.ACTIVITY_DETECTED);
        // add data (parcelable DetectedActivity)
        intent.putExtra(ActivityRecognitionService.MOTION_EVENT, motion);
        LocalBroadcastManager.getInstance( this ).sendBroadcast(intent);
    }

}




Java Source Code List

org.hopto.mjancola.ActivityTrackerApplication.java
org.hopto.mjancola.activity.ActivityRecognitionActivity.java
org.hopto.mjancola.activity.ActivityTracker.java
org.hopto.mjancola.activity.DemoDetailsList.java
org.hopto.mjancola.activity.DemoDetails.java
org.hopto.mjancola.activity.EditWorkoutDAOActivity.java
org.hopto.mjancola.activity.FeatureView.java
org.hopto.mjancola.activity.LegalInfoActivity.java
org.hopto.mjancola.activity.ListWorkoutsActivity.java
org.hopto.mjancola.activity.MyLocationDemoActivity.java
org.hopto.mjancola.activity.SpeedActivity.java
org.hopto.mjancola.activity.UserSettingsActivity.java
org.hopto.mjancola.adapter.WorkoutDAOAdapter.java
org.hopto.mjancola.fragment.EditWorkoutDAOFragment.java
org.hopto.mjancola.model.DataPoint.java
org.hopto.mjancola.model.GenericMovement.java
org.hopto.mjancola.model.GenericWorkout.java
org.hopto.mjancola.model.LearningMode.java
org.hopto.mjancola.model.MyMovement.java
org.hopto.mjancola.model.WorkoutTotal.java
org.hopto.mjancola.model.WorkoutType.java
org.hopto.mjancola.model.Workout.java
org.hopto.mjancola.service.ActivityRecognitionService.java
org.hopto.mjancola.service.MovementListenerService.java
org.hopto.mjancola.service.MovementTrackerService.java
org.hopto.mjancola.utility.Converter.java
org.hopto.mjancola.utility.MySQLiteHelper.java
org.hopto.mjancola.utility.SettingsHelper.java
org.hopto.mjancola.utility.WorkoutDAO.java
org.hopto.mjancola.utility.WorkoutDataSource.java