Android Open Source - activity-tracker Activity Recognition Service

From Project

Back to project page activity-tracker.


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.content.Intent;
import android.util.Log;

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" );

    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

    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