Search in sources :

Example 1 with ActivityRecognitionClient

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);
}
Also used : DetectedActivity(com.google.android.gms.location.DetectedActivity) ListView(android.widget.ListView) ActivityRecognitionClient(com.google.android.gms.location.ActivityRecognitionClient)

Example 2 with ActivityRecognitionClient

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));
}
Also used : IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ActivityRecognitionClient(com.google.android.gms.location.ActivityRecognitionClient)

Example 3 with ActivityRecognitionClient

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);
}
Also used : ActivityRecognitionClient(com.google.android.gms.location.ActivityRecognitionClient)

Aggregations

ActivityRecognitionClient (com.google.android.gms.location.ActivityRecognitionClient)3 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ListView (android.widget.ListView)1 DetectedActivity (com.google.android.gms.location.DetectedActivity)1