Android Open Source - Rejsekort-Reminder Activity Sensor Intent Service






From Project

Back to project page Rejsekort-Reminder.

License

The source code is released under:

GNU General Public License

If you think the Android project Rejsekort-Reminder 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.example.publictransportation.sensors;
//from  w  ww  .  j av  a  2s. co m
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;

/**
 * Service that receives ActivityRecognition updates. It receives updates
 * in the background, even if the main Activity is not visible.
 */
public class ActivitySensorIntentService extends IntentService { 

  int cutoff;

  final public static String CONFIDENCE = "CONFIDENCE";
  final public static String ACTIVITY = "ACTIVITY";
  final public static String ACTIVITY_RECOGNITION_DATA = "ACTIVITY_RECOGNITION_DATA";

  public ActivitySensorIntentService() {
    // Set the label for the service's background thread
    super("ActivitySensorIntentService");
    Log.i("AS Service", "got to the intent service!");
  }

  /**
   * Called when a new activity detection update is available.
   */
  @Override
  protected void onHandleIntent(Intent intent) {
    Log.i("AS Service", "onHandleIntent: Got here!");
    if (ActivityRecognitionResult.hasResult(intent)) {
      // Get the update
      ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

      DetectedActivity mostProbableActivity = result.getMostProbableActivity();

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

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

      // process 
      Intent broadcastIntent = new Intent(ACTIVITY_RECOGNITION_DATA);
      broadcastIntent.putExtra(ACTIVITY, activityType);
      broadcastIntent.putExtra(CONFIDENCE, confidence);
      LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);

      Log.i("AS Service","Sent a local broardcast with the activity data.");

    }
    Log.i("AS", "onHandleIntent called");
  }
}




Java Source Code List

com.example.publictransportation.MainActivity.java
com.example.publictransportation.WidgetProvider.java
com.example.publictransportation.modes.AbstractMode.java
com.example.publictransportation.modes.ActivityResults.java
com.example.publictransportation.modes.BusMode.java
com.example.publictransportation.modes.DefaultMode.java
com.example.publictransportation.modes.ForcedMode.java
com.example.publictransportation.modes.MetroMode.java
com.example.publictransportation.modes.ModeTypes.java
com.example.publictransportation.modes.MovingMode.java
com.example.publictransportation.modes.STrainMode.java
com.example.publictransportation.modes.WaitingMode.java
com.example.publictransportation.profiles.AbstractProfile.java
com.example.publictransportation.profiles.DefaultProfile.java
com.example.publictransportation.sensors.AbstractSensor.java
com.example.publictransportation.sensors.ActivitySensorIntentService.java
com.example.publictransportation.sensors.ActivitySensor.java
com.example.publictransportation.sensors.CellSensor.java
com.example.publictransportation.sensors.SensorTypes.java
com.example.publictransportation.sensors.TimeSensor.java
com.example.publictransportation.sensors.WifiGroup.java
com.example.publictransportation.sensors.WifiSensor.java
com.example.publictransportation.service.IModeManager.java
com.example.publictransportation.service.LogItem.java
com.example.publictransportation.service.LogTypes.java
com.example.publictransportation.service.Logger.java
com.example.publictransportation.service.TrackerService.java