Session | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Analyze
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Nested Classes | Constants | Inherited Constants | Fields | Methods | Inherited Methods | [Expand All]
public class

# Session

extends Object
implements Parcelable

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:

- startTime: the timestamp when the session started. This is a mandatory field.
- endTimeMillis: the timestamp when the session ended. 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)
              .setStartTime(startTime, TimeUnit.MILLISECONDS)
              .setEndTime(endTime, TimeUnit.MILLISECONDS)
              .setActivity(FitnessActivities.BIKING)
              .build();

##### See Also

- `SessionsApi`

## Summary

Nested Classes
class | Session.Builder | Builder used to create new Sessions.

Constants
String | EXTRA_SESSION | Name for the parcelable intent extra containing a session.
String | MIME_TYPE_PREFIX | The common prefix for session MIME types.

[Expand] Inherited Constants
From interface android.os.Parcelable
int | CONTENTS_FILE_DESCRIPTOR |
int | PARCELABLE_WRITE_RETURN_VALUE |

Fields
public static final Creator<Session> | CREATOR |

Public Methods
int | describeContents()
boolean | equals(Object o)
static Session | extract(Intent intent) Extracts the session extra from the given intent, such as a callback intent received after registering to session start/end notifications, or an intent to view a session.
String | 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 | getEndTime(TimeUnit timeUnit) Returns the end time for the session, in the given unit since epoch.
String | getIdentifier() Returns the identifier for this session, if set.
static String | getMimeType(String activity) Returns the MIME type which describes a Session for a particular activity.
String | getName() Returns the name for this session.
long | getStartTime(TimeUnit timeUnit) Returns the start time for the session, in the given time unit 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
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
From interface android.os.Parcelable
abstract int | describeContents()
abstract void | writeToParcel(Parcel arg0, int arg1)

## Constants

#### public static final String EXTRA_SESSION

Name for the parcelable intent extra containing a session. It can be extracted using `extract(Intent)`.

Constant Value: "vnd.google.fitness.session"

#### public static final String MIME_TYPE_PREFIX

The common prefix for session MIME types. The MIME type for a particular session will be this prefix followed by the session's activity name. Examples:

     vnd.google.fitness.session/running
     vnd.google.fitness.session/volleyball.beach

The session's activity type is returned by `getActivity()`. The MIME type can be computed from the activity using `getMimeType(String)`
Constant Value: "vnd.google.fitness.session/"

## Fields

#### public static final Creator<Session> CREATOR

## Public Methods

#### public int describeContents ()

#### public boolean equals (Object o)

#### public static Session extract (Intent intent)

Extracts the session extra from the given intent, such as a callback intent received after registering to session start/end notifications, or an intent to view a session.

##### Returns

- the extracted Session, or `null` if the given intent does not contain a Session

#### public String 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 getEndTime (TimeUnit timeUnit)

Returns the end time for the session, in the given unit 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 static String getMimeType (String activity)

Returns the MIME type which describes a Session for a particular activity. The MIME type is used in intents such as the session view intent.

##### Parameters

activity | one of the activities in `FitnessActivities`.

#### public String getName ()

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

#### public long getStartTime (TimeUnit timeUnit)

Returns the start time for the session, in the given time unit 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)