public class

Session

extends Object
implements SafeParcelable
java.lang.Object
   ↳ com.google.android.gms.fitness.data.Session

Class Overview

A Session represents a time interval with associated metadata. Sessions provide a mechanism to store user-visible groups of related stream data in a useful and shareable manner, and allows for easy querying of the data in a detailed or aggregated fashion. The start and end times for sessions will be controlled by applications, and can be used to represent user-friendly groupings of activities, such as "bike ride", "marathon training run", etc. Any data in Google Fit which falls within this time range is implicitly associated with the session.

A session consists of the following fields:

  • startTimeMillis: the time when the session started, in milliseconds since epoch. This is a mandatory field.
  • endTimeMillis: the time when the session ended, in milliseconds since epoch. If not specified, the session is considered to be still ongoing. If specified, the end time should be strictly later than the start time. This is an optional field.
  • name: a human readable name, possibly specified by the user. For instance, "Sunday bike ride"
  • identifier: a unique identifier for the session. Should be unique for the given application and user. The application can use this identifier to later fetch a particular session. If the identifier is not specified, one will be created from the start time and name.
  • description: description of the session. Can be filled in by the user with specific notes for the session. This is an optional field.
  • activity: the activity associated with this session; for instance, biking. Can be used to identify sessions that encompass a single user activity. This is an optional field.
  • packageName: the package name of the application that added this session. This is inferred automatically by the Fitness Platform.

Example usage:

     new Session.Builder()
          .setName(sessionName)
          .setIdentifier(identifier)
          .setDescription(description)
          .setStartTimeMillis(startTime.getMillis())
          .setEndTimeMillis(endTime.getMillis())
          .setActivity(FitnessActivities.BIKING)
          .build();
 

See Also

Summary

Nested Classes
class Session.Builder Builder used to create new Sessions. 
[Expand]
Inherited Constants
From interface android.os.Parcelable
From interface com.google.android.gms.common.internal.safeparcel.SafeParcelable
Fields
public static final Creator<Session> CREATOR
Public Methods
int describeContents()
boolean equals(Object o)
static Session extract(Intent intent)
Extracts a session from a callback intent received after registering to session start/end notifications with a PendingIntent.
int getActivity()
Returns the activity associated with this session, if set.
String getAppPackageName()
Returns the package name for the application responsible for adding the session.
String getDescription()
Returns the description for this session, if set.
long getEndTimeMillis()
Returns the end time for the session, in milliseconds since epoch.
String getIdentifier()
Returns the identifier for this session, if set.
String getName()
Returns the name for this session.
long getStartTimeMillis()
Returns the start time for the session, in milliseconds since epoch.
int hashCode()
boolean isOngoing()
Returns whether the session is ongoing.
String toString()
void writeToParcel(Parcel dest, int flags)
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Fields

public static final Creator<Session> CREATOR

Public Methods

public int describeContents ()

public boolean equals (Object o)

public static Session extract (Intent intent)

Extracts a session from a callback intent received after registering to session start/end notifications with a PendingIntent.

Returns
  • the extracted Session, or null if the given intent does not contain a Session

public int getActivity ()

Returns the activity associated with this session, if set. Else returns UNKNOWN.

public String getAppPackageName ()

Returns the package name for the application responsible for adding the session. or null if unset/unknown. The PackageManager can be used to query relevant data on the application, such as the name, icon, logo, etc.

public String getDescription ()

Returns the description for this session, if set.

public long getEndTimeMillis ()

Returns the end time for the session, in milliseconds since epoch. If the session is ongoing (it hasn't ended yet), this will return 0.

public String getIdentifier ()

Returns the identifier for this session, if set.

public String getName ()

Returns the name for this session. A non-empty name is always set.

public long getStartTimeMillis ()

Returns the start time for the session, in milliseconds since epoch. A valid start time is always set.

public int hashCode ()

public boolean isOngoing ()

Returns whether the session is ongoing. If the session has ended, this will return false.

public String toString ()

public void writeToParcel (Parcel dest, int flags)