use of com.google.android.gms.location.ActivityRecognitionClient in project android-play-location by googlesamples.
the class MainActivity method onCreate.
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mContext = this;
// Get the UI widgets.
mRequestActivityUpdatesButton = (Button) findViewById(R.id.request_activity_updates_button);
mRemoveActivityUpdatesButton = (Button) findViewById(R.id.remove_activity_updates_button);
ListView detectedActivitiesListView = (ListView) findViewById(R.id.detected_activities_listview);
// Enable either the Request Updates button or the Remove Updates button depending on
// whether activity updates have been requested.
setButtonsEnabledState();
ArrayList<DetectedActivity> detectedActivities = Utils.detectedActivitiesFromJson(PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.KEY_DETECTED_ACTIVITIES, ""));
// Bind the adapter to the ListView responsible for display data for detected activities.
mAdapter = new DetectedActivitiesAdapter(this, detectedActivities);
detectedActivitiesListView.setAdapter(mAdapter);
mActivityRecognitionClient = new ActivityRecognitionClient(this);
}
use of com.google.android.gms.location.ActivityRecognitionClient in project androidApp by InspectorIncognito.
the class ActivityDetectionHandler method startActivityUpdates.
public void startActivityUpdates(GoogleApiClient googleApiClient) {
this.googleApiClient = googleApiClient;
Intent intent = new Intent(context, DetectedActivitiesIntentService.class);
pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
ActivityRecognitionClient activityRecognitionClient = ActivityRecognition.getClient(context);
activityRecognitionClient.requestActivityUpdates(3000, pendingIntent);
LocalBroadcastManager.getInstance(context).registerReceiver(broadcastReceiver, new IntentFilter(Constants.ACTIVITY_BROADCAST_ACTION));
}
use of com.google.android.gms.location.ActivityRecognitionClient in project androidApp by InspectorIncognito.
the class ActivityDetectionHandler method stopActivityUpdates.
public void stopActivityUpdates() {
ActivityRecognitionClient activityRecognitionClient = ActivityRecognition.getClient(context);
activityRecognitionClient.removeActivityUpdates(pendingIntent);
this.googleApiClient.disconnect();
LocalBroadcastManager.getInstance(context).unregisterReceiver(broadcastReceiver);
}
Aggregations