Android Open Source - android_sensor_logger Activity Recognition Intent Service






From Project

Back to project page android_sensor_logger.

License

The source code is released under:

MIT License

If you think the Android project android_sensor_logger 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.pinsonault.androidsensorlogger;
//from  w ww . j a  v  a2 s  .  c  om
import android.app.IntentService;
import android.content.Intent;

import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity;

/**
* Service that receives ActivityRecognition updates. It receives updates
* in the background, even if the main Activity is not visible.
*/
public class ActivityRecognitionIntentService extends IntentService {
    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public ActivityRecognitionIntentService(String name) {
        super(name);
    }

    public ActivityRecognitionIntentService() {
        super("Activity Recognition Service");
    }

    /**
     * Called when a new activity detection update is available.
     */
    @Override
    protected void onHandleIntent(Intent intent) {
        //...
        // If the intent contains an update
        if (ActivityRecognitionResult.hasResult(intent)) {
            // Get the updatenex
            ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

            DetectedActivity mostProbableActivity = result.getMostProbableActivity();

            // Get the confidence % (probability)
            int confidence = mostProbableActivity.getConfidence();

            // Get the type
            int activityType = mostProbableActivity.getType();

            Intent sendToLoggerIntent = new Intent("com.pinsonault.androidsensorlogger.ACTIVITY_RECOGNITION_DATA");
            sendToLoggerIntent.putExtra("Activity", activityType);
            sendToLoggerIntent.putExtra("Confidence", confidence);
            sendBroadcast(sendToLoggerIntent);
        }
    }

    private static String getFriendlyName(int detected_activity_type) {
        switch (detected_activity_type) {
            case DetectedActivity.IN_VEHICLE:
                return "vehicle";
            case DetectedActivity.ON_BICYCLE:
                return "bike";
            case DetectedActivity.ON_FOOT:
                return "foot";
            case DetectedActivity.TILTING:
                return "tilting";
            case DetectedActivity.STILL:
                return "still";
            default:
                return "unknown";
        }
    }
}




Java Source Code List

android.UnusedStub.java
com.asl_play_services.MyClass.java
com.pinsonault.androidsensorlogger.ActivityRecognitionIntentService.java
com.pinsonault.androidsensorlogger.ActivityRecognitionScan.java
com.pinsonault.androidsensorlogger.LoggerServiceReceiver.java
com.pinsonault.androidsensorlogger.LoggerService.java
com.pinsonault.androidsensorlogger.MainActivity.java