-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDetectedActivitiesIntentService.java
More file actions
54 lines (41 loc) · 1.78 KB
/
DetectedActivitiesIntentService.java
File metadata and controls
54 lines (41 loc) · 1.78 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
package info.androidhive.activityrecognition;
/**
* Created by ravi on 16/12/17.
*/
import android.app.IntentService;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity;
import java.util.ArrayList;
public class DetectedActivitiesIntentService extends IntentService {
protected static final String TAG = DetectedActivitiesIntentService.class.getSimpleName();
public DetectedActivitiesIntentService() {
// Use the TAG to name the worker thread.
super(TAG);
}
@Override
public void onCreate() {
super.onCreate();
}
@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();
for (DetectedActivity activity : detectedActivities) {
Log.i(TAG, "Detected activity: " + activity.getType() + ", " + activity.getConfidence());
broadcastActivity(activity);
}
}
private void broadcastActivity(DetectedActivity activity) {
Intent intent = new Intent(Constants.BROADCAST_DETECTED_ACTIVITY);
intent.putExtra("type", activity.getType());
intent.putExtra("confidence", activity.getConfidence());
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
}