-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathActivityRecognizedService.java
More file actions
84 lines (77 loc) · 3.33 KB
/
ActivityRecognizedService.java
File metadata and controls
84 lines (77 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package edu.stonybrook.aadarshcs.gpsplanner;
import android.app.IntentService;
import android.content.Intent;
import android.content.Context;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.NotificationCompat;
import android.util.Log;
import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity;
import java.util.List;
/**
* An {@link IntentService} subclass for handling asynchronous task requests in
* a service on a separate handler thread.
* <p>
* TODO: Customize class - update intent actions, extra parameters and static
* helper methods.
*/
public class ActivityRecognizedService extends IntentService {
public ActivityRecognizedService() {
super("ActivityRecognizedService");
}
public ActivityRecognizedService(String name) {
super(name);
}
@Override
protected void onHandleIntent(Intent intent) {
if(ActivityRecognitionResult.hasResult(intent)) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
handleDetectedActivities( result.getProbableActivities() );
}
}
private void handleDetectedActivities(List<DetectedActivity> probableActivities) {
for( DetectedActivity activity : probableActivities ) {
switch( activity.getType() ) {
case DetectedActivity.IN_VEHICLE: {
Log.e( "ActivityRecogition", "In Vehicle: " + activity.getConfidence() );
break;
}
case DetectedActivity.ON_BICYCLE: {
Log.e( "ActivityRecogition", "On Bicycle: " + activity.getConfidence() );
break;
}
case DetectedActivity.ON_FOOT: {
Log.e( "ActivityRecogition", "On Foot: " + activity.getConfidence() );
break;
}
case DetectedActivity.RUNNING: {
Log.e( "ActivityRecogition", "Running: " + activity.getConfidence() );
break;
}
case DetectedActivity.STILL: {
Log.e( "ActivityRecogition", "Still: " + activity.getConfidence() );
break;
}
case DetectedActivity.TILTING: {
Log.e( "ActivityRecogition", "Tilting: " + activity.getConfidence() );
break;
}
case DetectedActivity.WALKING: {
Log.e( "ActivityRecogition", "Walking: " + activity.getConfidence() );
if( activity.getConfidence() >= 75 ) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentText( "Are you walking?" );
builder.setSmallIcon( R.mipmap.ic_launcher );
builder.setContentTitle( getString( R.string.app_name ) );
NotificationManagerCompat.from(this).notify(0, builder.build());
}
break;
}
case DetectedActivity.UNKNOWN: {
Log.e( "ActivityRecogition", "Unknown: " + activity.getConfidence() );
break;
}
}
}
}
}