|
|
@ -4,7 +4,6 @@ import android.app.* |
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.content.Intent |
|
|
|
import android.content.Intent |
|
|
|
import android.content.pm.PackageManager |
|
|
|
import android.content.pm.PackageManager |
|
|
|
import android.graphics.Color |
|
|
|
|
|
|
|
import android.hardware.Sensor |
|
|
|
import android.hardware.Sensor |
|
|
|
import android.hardware.SensorEvent |
|
|
|
import android.hardware.SensorEvent |
|
|
|
import android.hardware.SensorEventListener |
|
|
|
import android.hardware.SensorEventListener |
|
|
@ -100,7 +99,7 @@ class EndlessService : Service(), SensorEventListener, LocationListener { |
|
|
|
mSensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager |
|
|
|
mSensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager |
|
|
|
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) |
|
|
|
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) |
|
|
|
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) |
|
|
|
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) |
|
|
|
// setupActivityRecognitionUpdates() |
|
|
|
setupActivityRecognitionUpdates() |
|
|
|
|
|
|
|
|
|
|
|
if (checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { |
|
|
|
if (checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { |
|
|
|
mLocationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager |
|
|
|
mLocationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager |
|
|
@ -120,6 +119,12 @@ class EndlessService : Service(), SensorEventListener, LocationListener { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getActivityTransitionPendingIntent(): PendingIntent { |
|
|
|
|
|
|
|
val intent = Intent(this, ActivityTransitionIntentService::class.java) |
|
|
|
|
|
|
|
return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun setupActivityRecognitionUpdates() { |
|
|
|
private fun setupActivityRecognitionUpdates() { |
|
|
|
// ActivityRecognition |
|
|
|
// ActivityRecognition |
|
|
|
val transitions = mutableListOf<ActivityTransition>() |
|
|
|
val transitions = mutableListOf<ActivityTransition>() |
|
|
@ -128,35 +133,46 @@ class EndlessService : Service(), SensorEventListener, LocationListener { |
|
|
|
.setActivityType(DetectedActivity.IN_VEHICLE) |
|
|
|
.setActivityType(DetectedActivity.IN_VEHICLE) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER) |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
transitions += |
|
|
|
/*transitions += |
|
|
|
ActivityTransition.Builder() |
|
|
|
ActivityTransition.Builder() |
|
|
|
.setActivityType(DetectedActivity.IN_VEHICLE) |
|
|
|
.setActivityType(DetectedActivity.IN_VEHICLE) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT) |
|
|
|
.build() |
|
|
|
.build()*/ |
|
|
|
transitions += |
|
|
|
transitions += |
|
|
|
ActivityTransition.Builder() |
|
|
|
ActivityTransition.Builder() |
|
|
|
.setActivityType(DetectedActivity.ON_BICYCLE) |
|
|
|
.setActivityType(DetectedActivity.ON_BICYCLE) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER) |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
transitions += |
|
|
|
/*transitions += |
|
|
|
ActivityTransition.Builder() |
|
|
|
ActivityTransition.Builder() |
|
|
|
.setActivityType(DetectedActivity.ON_BICYCLE) |
|
|
|
.setActivityType(DetectedActivity.ON_BICYCLE) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT) |
|
|
|
.build() |
|
|
|
.build()*/ |
|
|
|
transitions += |
|
|
|
transitions += |
|
|
|
ActivityTransition.Builder() |
|
|
|
ActivityTransition.Builder() |
|
|
|
.setActivityType(DetectedActivity.WALKING) |
|
|
|
.setActivityType(DetectedActivity.WALKING) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER) |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
transitions += |
|
|
|
/*transitions += |
|
|
|
ActivityTransition.Builder() |
|
|
|
ActivityTransition.Builder() |
|
|
|
.setActivityType(DetectedActivity.WALKING) |
|
|
|
.setActivityType(DetectedActivity.WALKING) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT) |
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT) |
|
|
|
|
|
|
|
.build()*/ |
|
|
|
|
|
|
|
transitions += |
|
|
|
|
|
|
|
ActivityTransition.Builder() |
|
|
|
|
|
|
|
.setActivityType(DetectedActivity.STILL) |
|
|
|
|
|
|
|
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER) |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
val request = ActivityTransitionRequest(transitions) |
|
|
|
val request = ActivityTransitionRequest(transitions) |
|
|
|
|
|
|
|
val pendingIntent = getActivityTransitionPendingIntent() |
|
|
|
mActivityRecognitionClient = ActivityRecognition.getClient(applicationContext) |
|
|
|
mActivityRecognitionClient = ActivityRecognition.getClient(applicationContext) |
|
|
|
mActivityRecognitionClient.requestActivityTransitionUpdates(request, null) |
|
|
|
val task = |
|
|
|
|
|
|
|
mActivityRecognitionClient.requestActivityTransitionUpdates(request, pendingIntent) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
task.addOnSuccessListener { log("ACT_TRANSITION: success listener") } |
|
|
|
|
|
|
|
task.addOnFailureListener { exception -> |
|
|
|
|
|
|
|
log("ACT_TRANSITION: failed $exception") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
override fun onDestroy() { |
|
|
@ -310,7 +326,8 @@ class EndlessService : Service(), SensorEventListener, LocationListener { |
|
|
|
val (bytes, error) = result |
|
|
|
val (bytes, error) = result |
|
|
|
if (bytes != null) { |
|
|
|
if (bytes != null) { |
|
|
|
log("[response bytes] ${String(bytes)}") |
|
|
|
log("[response bytes] ${String(bytes)}") |
|
|
|
val notification = createNotification("[req] ${gmtTime} - ${String(bytes)}") |
|
|
|
val notification = |
|
|
|
|
|
|
|
createNotification("[req] ${gmtTime} - ${String(bytes)}") |
|
|
|
nm.notify(notificationId, notification) |
|
|
|
nm.notify(notificationId, notification) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log("[response error] ${error?.message}") |
|
|
|
log("[response error] ${error?.message}") |
|
|
@ -330,13 +347,13 @@ class EndlessService : Service(), SensorEventListener, LocationListener { |
|
|
|
val channel = NotificationChannel( |
|
|
|
val channel = NotificationChannel( |
|
|
|
notificationChannelId, |
|
|
|
notificationChannelId, |
|
|
|
"SL notifications channel", |
|
|
|
"SL notifications channel", |
|
|
|
NotificationManager.IMPORTANCE_DEFAULT |
|
|
|
NotificationManager.IMPORTANCE_LOW |
|
|
|
).let { |
|
|
|
).let { |
|
|
|
it.description = "SL Service channel" |
|
|
|
it.description = "SL Service channel" |
|
|
|
it.enableLights(true) |
|
|
|
it.enableLights(false) |
|
|
|
it.lightColor = Color.RED |
|
|
|
//it.lightColor = Color.RED |
|
|
|
it.enableVibration(true) |
|
|
|
it.enableVibration(false) |
|
|
|
it.vibrationPattern = longArrayOf(100, 200, 300, 400, 500, 400, 300, 200, 400) |
|
|
|
//it.vibrationPattern = longArrayOf(100, 200, 300, 400, 500, 400, 300, 200, 400) |
|
|
|
it |
|
|
|
it |
|
|
|
} |
|
|
|
} |
|
|
|
nm.createNotificationChannel(channel) |
|
|
|
nm.createNotificationChannel(channel) |
|
|
|