Search in sources :

Example 1 with ActivityRecognitionResult

use of com.google.android.gms.location.ActivityRecognitionResult in project xDrip by NightscoutFoundation.

the class ActivityRecognizedService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    final PowerManager.WakeLock wl = JoH.getWakeLock(TAG, 60000);
    try {
        if (intent.getStringExtra(START_ACTIVITY_ACTION) != null) {
            start(true);
        } else if (intent.getStringExtra(RESTART_ACTIVITY_ACTION) != null) {
            restart(FREQUENCY);
            checkVehicleRepeatNotification();
        } else if (intent.getStringExtra(STOP_ACTIVITY_ACTION) != null) {
            UserError.Log.uel(TAG, "Stopping service");
            stop();
        } else if (intent.getStringExtra(RECHECK_VEHICLE_MODE) != null) {
            checkVehicleRepeatNotification();
        } else if (ActivityRecognitionResult.hasResult(intent)) {
            if ((Pref.getBooleanDefaultFalse("motion_tracking_enabled"))) {
                if (mApiClient == null)
                    start();
                ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
                final int topConfidence = handleDetectedActivities(result.getProbableActivities(), true, 0);
                last_data = JoH.ts();
                received++;
                if (d)
                    Log.d(TAG, JoH.hourMinuteString() + " :: Packets received: " + received + " Top confidence: " + topConfidence);
                if ((received > MAX_RECEIVED) || (topConfidence > 90))
                    // one hit only
                    stopUpdates();
            } else {
                // / DEEEBUG
                UserError.Log.wtf(TAG, "Received ActivityRecognition we were not expecting!");
            }
        } else {
            // spoof from intent
            final String payload = intent.getStringExtra(INCOMING_ACTIVITY_ACTION);
            if ((payload != null) && (Pref.getBoolean("use_remote_motion", false))) {
                try {
                    final String[] amup = payload.split("\\^");
                    final long timestamp = Long.parseLong(amup[0]);
                    final int activity = Integer.parseInt(amup[1]);
                    final List<DetectedActivity> incoming_list = new ArrayList<>();
                    incoming_list.add(new DetectedActivity(activity, 101));
                    handleDetectedActivities(incoming_list, false, timestamp);
                } catch (Exception e) {
                    Log.wtf(TAG, "Exception processing incoming motion: " + e.toString());
                }
            }
        }
    } finally {
        JoH.releaseWakeLock(wl);
    }
}
Also used : PowerManager(android.os.PowerManager) DetectedActivity(com.google.android.gms.location.DetectedActivity) ArrayList(java.util.ArrayList) ActivityRecognitionResult(com.google.android.gms.location.ActivityRecognitionResult)

Example 2 with ActivityRecognitionResult

use of com.google.android.gms.location.ActivityRecognitionResult in project stillStanding by katsik.

the class ActivityRecognizedService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        // handleDetectedActivities(result.getProbableActivities());
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();
        int confidence = mostProbableActivity.getConfidence();
        int activityType = mostProbableActivity.getType();
        /*types:
            * DetectedActivity.IN_VEHICLE
            * DetectedActivity.ON_BICYCLE
            * DetectedActivity.ON_FOOT
            * DetectedActivity.STILL
            * DetectedActivity.UNKNOWN
            * DetectedActivity.TILTING
            */
        handleDetectedActivities(mostProbableActivity);
    }
}
Also used : DetectedActivity(com.google.android.gms.location.DetectedActivity) ActivityRecognitionResult(com.google.android.gms.location.ActivityRecognitionResult)

Example 3 with ActivityRecognitionResult

use of com.google.android.gms.location.ActivityRecognitionResult in project android-play-location by googlesamples.

the class DetectedActivitiesIntentService method onHandleIntent.

/**
 * Handles incoming intents.
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@SuppressWarnings("unchecked")
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();
    PreferenceManager.getDefaultSharedPreferences(this).edit().putString(Constants.KEY_DETECTED_ACTIVITIES, Utils.detectedActivitiesToJson(detectedActivities)).apply();
    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da : detectedActivities) {
        Log.i(TAG, Utils.getActivityString(getApplicationContext(), da.getType()) + " " + da.getConfidence() + "%");
    }
}
Also used : DetectedActivity(com.google.android.gms.location.DetectedActivity) ArrayList(java.util.ArrayList) ActivityRecognitionResult(com.google.android.gms.location.ActivityRecognitionResult)

Example 4 with ActivityRecognitionResult

use of com.google.android.gms.location.ActivityRecognitionResult in project androidApp by InspectorIncognito.

the class DetectedActivitiesIntentService method onHandleIntent.

/**
 * Handles incoming intents.
 *
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    Intent localIntent = new Intent(Constants.ACTIVITY_BROADCAST_ACTION);
    if (result == null) {
        return;
    }
    ArrayList<DetectedActivity> res = new ArrayList<>();
    for (DetectedActivity d : result.getProbableActivities()) {
        if (d.getConfidence() > Constants.MIN_ACTIVITY_CONFIDENCE) {
            res.add(d);
        }
    }
    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, res);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
Also used : DetectedActivity(com.google.android.gms.location.DetectedActivity) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ActivityRecognitionResult(com.google.android.gms.location.ActivityRecognitionResult)

Example 5 with ActivityRecognitionResult

use of com.google.android.gms.location.ActivityRecognitionResult in project DataLogger by sussexwearlab.

the class HARecognizerApiIntentService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();
    // Broadcast the list of detected activities.
    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Constants.BROADCAST_ACTION).putExtra(Constants.DETECTED_ACTIVITIES_INTENT_KEY, detectedActivities));
}
Also used : DetectedActivity(com.google.android.gms.location.DetectedActivity) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ActivityRecognitionResult(com.google.android.gms.location.ActivityRecognitionResult)

Aggregations

ActivityRecognitionResult (com.google.android.gms.location.ActivityRecognitionResult)6 DetectedActivity (com.google.android.gms.location.DetectedActivity)6 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)2 PowerManager (android.os.PowerManager)2