Java Code Examples for com.google.android.gms.location.ActivityRecognitionResult#hasResult()

The following examples show how to use com.google.android.gms.location.ActivityRecognitionResult#hasResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SKActivityRecognitionIntentService.java    From SensingKit-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {

    // If the intent contains an update
    if (ActivityRecognitionResult.hasResult(intent)) {

        // Get the update
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

        Intent i = new Intent(BROADCAST_UPDATE);
        i.putExtra(RECOGNITION_RESULT, result);
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
        manager.sendBroadcast(i);
    }

}
 
Example 2
Source File: MotionIntentService.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void onHandleIntent(final Intent intent) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "onHandleIntent");
    }

    if (SPH.getMotionEnabled(getApplicationContext())) {

        if (intent != null) {
            if (DEBUG) {
                examineIntent(intent);
            }

            if (ActivityRecognitionResult.hasResult(intent)) {
                final Motion motion = extractMotion(intent);
                if (motion != null) {
                    MotionHelper.setMotion(getApplicationContext(), motion);
                } else {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "onHandleIntent: motion null: ignoring");
                    }
                }
            } else {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "onHandleIntent: no ActivityRecognition results");
                }
            }
        } else {
            if (DEBUG) {
                MyLog.w(CLS_NAME, "onHandleIntent: intent: null");
            }
        }
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "onHandleIntent: user has switched off. Don't store.");
        }
    }
}
 
Example 3
Source File: ActivityRecognizedService.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    if(ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        handleDetectedActivities( result.getProbableActivities() );
    }
}
 
Example 4
Source File: AndroidActivityRecognitionWrapper.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void runOnce() {
	if (!isRunning()) {
		disconnectGoogleAPI();
	} else {
		if (mGoogleApiClient == null) {
			connectGoogleAPI();
		}
		updateWrapperInfo();

		if (ActivityRecognitionResult.hasResult(ActivityRecognitionService.getIntent())) {
			// Get the update
			ActivityRecognitionResult result =
					ActivityRecognitionResult.extractResult(ActivityRecognitionService.getIntent());

			DetectedActivity mostProbableActivity
					= result.getMostProbableActivity();

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

			// Get the type
			double activityType = mostProbableActivity.getType();
	   /* types:
	    * DetectedActivity.IN_VEHICLE
           * DetectedActivity.ON_BICYCLE
           * DetectedActivity.ON_FOOT
           * DetectedActivity.STILL
           * DetectedActivity.UNKNOWN
           * DetectedActivity.TILTING
           */
			StreamElement streamElement = new StreamElement(FIELD_NAMES, FIELD_TYPES,
					                                               new Serializable[]{activityType, confidence});
			postStreamElement(streamElement);
		} else {
			Log.d(TAG, "No results for AndroidActivityRecognition");
		}
	}
}
 
Example 5
Source File: ActivityRecognitionIntentService.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    ((PebbleBikeApplication)getApplication()).inject(this);

    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

        switch(result.getMostProbableActivity().getType()) {

            case DetectedActivity.ON_BICYCLE:
                Log.d(TAG, "ON_BICYCLE");
                sendReply(result.getMostProbableActivity().getType());
                break;
            case DetectedActivity.WALKING:
                Log.d(TAG, "WALKING");
                sendReply(result.getMostProbableActivity().getType());
                break;
            case DetectedActivity.RUNNING:
                Log.d(TAG, "RUNNING");
                sendReply(result.getMostProbableActivity().getType());
                break;
            case DetectedActivity.ON_FOOT:
                Log.d(TAG, "ON_FOOT");
                sendReply(result.getMostProbableActivity().getType());
                break;
            case DetectedActivity.TILTING:
                Log.d(TAG, "TILTING");
                break;
            case DetectedActivity.STILL:
                Log.d(TAG, "STILL");
                sendReply(result.getMostProbableActivity().getType());
                break;
            default:
                logActivity(result);
        }
    }
}
 
Example 6
Source File: BackgroundService.java    From GeoLog with Apache License 2.0 5 votes vote down vote up
public boolean processIntent(Intent intent) {
	if (intent == null) return false;
	
	if (ActivityRecognitionResult.hasResult(intent)) {
		processActivity(intent);
		return true;
	} else if (intent.hasExtra(EXTRA_ALARM_CALLBACK)) {
		processAlarmCallback(intent);
		return true;
	}			
	
	return false;
}
 
Example 7
Source File: ActivityRecognitionIntentService.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
  if (!ActivityRecognitionResult.hasResult(intent)) {
    return;
  }
  ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
  DetectedActivity detectedActivity = result.getMostProbableActivity();
  if (detectedActivity == null) {
    return;
  }
  if (detectedActivity.getConfidence() < REQUIRED_CONFIDENCE) {
    return;
  }

  long recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
  if (recordingTrackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
    return;
  }
  boolean recordingTrackPaused = PreferencesUtils.getBoolean(
      this, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
  if (recordingTrackPaused) {
    return;
  }

  int currentType = PreferencesUtils.getInt(this, R.string.activity_recognition_type_key,
      PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT);

  switch (detectedActivity.getType()) {
    case DetectedActivity.IN_VEHICLE:
      if (currentType != DetectedActivity.IN_VEHICLE) {
        PreferencesUtils.setInt(
            this, R.string.activity_recognition_type_key, DetectedActivity.IN_VEHICLE);
      }
      break;
    case DetectedActivity.ON_BICYCLE:
      if (currentType != DetectedActivity.IN_VEHICLE
          && currentType != DetectedActivity.ON_BICYCLE) {
        PreferencesUtils.setInt(
            this, R.string.activity_recognition_type_key, DetectedActivity.ON_BICYCLE);
      }
      break;
    case DetectedActivity.ON_FOOT:
      if (currentType != DetectedActivity.IN_VEHICLE && currentType != DetectedActivity.ON_BICYCLE
          && currentType != DetectedActivity.ON_FOOT) {
        PreferencesUtils.setInt(
            this, R.string.activity_recognition_type_key, DetectedActivity.ON_FOOT);
      }
      break;
    default:
      break;
  }
}