public ActivityRecognitionController(Context context) { this.mContext = context.getApplicationContext(); this.mPreferenceUtils = new PreferenceUtils(mContext); this.mGClient = new GoogleApiClient.Builder(mContext) .addApi(ActivityRecognition.API) .addOnConnectionFailedListener(this) .addConnectionCallbacks(this) .build(); this.mClient = ActivityRecognition.ActivityRecognitionApi; }
public SKActivity(final Context context) throws SKException { super(context, SKSensorModuleType.ACTIVITY); mClient = new GoogleApiClient.Builder(context) .addApi(ActivityRecognition.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mActivityRecognition = ActivityRecognition.ActivityRecognitionApi; mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { ActivityRecognitionResult result = intent.getParcelableExtra(SKActivityRecognitionIntentService.RECOGNITION_RESULT); // Get activity from the list of activities DetectedActivity activity = getActivity(result); // Get the type of activity int activityType = activity.getType(); // Get the confidence percentage for the most probable activity int confidence = activity.getConfidence(); // Build the data object SKAbstractData data = new SKActivityData(result.getTime(), activityType, confidence); // Submit sensor data object submitSensorData(data); } }; }