Download File
Download Project
Settings
Line Wrap
Themes
default
ambiance
bespin
dracula
eclipse
material
mbo
mdn-like
neat
solarized dark
ttcn
zenburn
DetectedActivitiesIntentService.java
/** * Copyright 2017 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.android.gms.location.sample.activityrecognition; import android.app.IntentService; import android.content.Intent; import android.preference.PreferenceManager; import android.util.Log; import com.google.android.gms.location.ActivityRecognitionResult; import com.google.android.gms.location.DetectedActivity; import java.util.ArrayList; /** * IntentService for handling incoming intents that are generated as a result of requesting * activity updates using * {@link com.google.android.gms.location.ActivityRecognitionApi#requestActivityUpdates}. */ public class DetectedActivitiesIntentService extends IntentService { protected static final String TAG = "DetectedActivitiesIS"; /** * This constructor is required, and calls the super IntentService(String) * constructor with the name for a worker thread. */ public DetectedActivitiesIntentService() { // Use the TAG to name the worker thread. super(TAG); } @Override public void onCreate() { super.onCreate(); } /** * 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
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() + "%" ); } } }