use of com.google.android.gms.location.ActivityRecognitionResult in project xDrip-plus by jamorham.
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);
}
}
Aggregations