SessionsApi.ViewIntentBuilder
Stay organized with collections
Save and categorize content based on your preferences.
Builder of intents to view sessions
stored in Google Fit. This intent can be used when the application wants to display a more
detailed view of a particular session. Apps that can display sessions (such as the app that
inserted the session) can register for the given intent.
If the application which inserted the session is installed on the device, it'll be
preferred to handle the intent. This behavior can be overridden by
setPreferredApplication(String)
.
The session view intent has the following attributes:
- action is set to
Fitness.ACTION_VIEW
- type is
Session.MIME_TYPE_PREFIX
followed by the activity for the session. For example,
vnd.google.fitness.session/running
would represent a running session.
- extras containing the session
An application that would like to handle Session view intents should create an activity
and add an intent filter to its manifest file. Here's an example of an activity that can
display biking and running sessions:
<activity android:name=".ViewSessionActivity" android:exported="true">
<intent-filter>
<action android:name="vnd.google.fitness.VIEW" />
<data android:mimeType="vnd.google.fitness.session/biking" />
<data android:mimeType="vnd.google.fitness.session/running" />
</intent-filter>
</activity>
In addition, if the application is able to show sessions from other apps, it can add the
Intent.CATEGORY_DEFAULT
to the intent filter, as follows:
<category android:name="android.intent.category.DEFAULT" />
Public Constructor Summary
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Public Constructors
public ViewIntentBuilder (Context
context)
Public Methods
Sets a preferred application to use for this intent. If the given app is installed
and able to handle this intent, an explicit intent will be returned.
By default, the intent will attempt to use the application which inserted the
session. Use this method only to override that behavior.
Parameters
packageName |
The package name for the application to prefer for the intent, or
null to not prefer any application |
Returns
- This builder, for chaining.
Sets the session to display data for. A specific session must be set.
Parameters
session |
The specific session to show data for. |
Returns
- This builder, for chaining.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[null,null,["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eSessionsApi.ViewIntentBuilder\u003c/code\u003e helps create intents to view fitness sessions stored in Google Fit, allowing apps to display detailed session information.\u003c/p\u003e\n"],["\u003cp\u003eThe built intent can launch an activity in an app that has registered to handle session view intents, with the preferred application being the one that inserted the session, unless overridden.\u003c/p\u003e\n"],["\u003cp\u003eSession view intents contain the action \u003ccode\u003eFitness.ACTION_VIEW\u003c/code\u003e, the session's activity type as the MIME type, and the session data in extras.\u003c/p\u003e\n"],["\u003cp\u003eApps wanting to handle session view intents need to declare an activity with appropriate intent filters in their manifest, including \u003ccode\u003eFitness.ACTION_VIEW\u003c/code\u003e and relevant MIME types.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can specify a preferred application to handle the intent or let the system choose the app that inserted the session.\u003c/p\u003e\n"]]],[],null,["# SessionsApi.ViewIntentBuilder\n\npublic static class **SessionsApi.ViewIntentBuilder** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nBuilder of intents to view [sessions](/android/reference/com/google/android/gms/fitness/data/Session)\nstored in Google Fit. This intent can be used when the application wants to display a more\ndetailed view of a particular session. Apps that can display sessions (such as the app that\ninserted the session) can register for the given intent.\n\nIf the application which inserted the session is installed on the device, it'll be\npreferred to handle the intent. This behavior can be overridden by [setPreferredApplication(String)](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder#setPreferredApplication(java.lang.String)).\n\nThe session view intent has the following attributes:\n\n- **action** is set to [Fitness.ACTION_VIEW](/android/reference/com/google/android/gms/fitness/Fitness#ACTION_VIEW)\n- **type** is [Session.MIME_TYPE_PREFIX](/android/reference/com/google/android/gms/fitness/data/Session#MIME_TYPE_PREFIX) followed by the activity for the session. For example, `vnd.google.fitness.session/running` would represent a running session.\n- **extras** containing the session\n\nAn application that would like to handle Session view intents should create an activity\nand add an intent filter to its manifest file. Here's an example of an activity that can\ndisplay biking and running sessions: \n\n```\n \u003cactivity android:name=\".ViewSessionActivity\" android:exported=\"true\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"vnd.google.fitness.VIEW\" /\u003e\n \u003cdata android:mimeType=\"vnd.google.fitness.session/biking\" /\u003e\n \u003cdata android:mimeType=\"vnd.google.fitness.session/running\" /\u003e\n \u003c/intent-filter\u003e\n \u003c/activity\u003e\n \n```\nIn addition, if the application is able to show sessions from other apps, it can add the [Intent.CATEGORY_DEFAULT](//developer.android.com/reference/android/content/Intent.html#CATEGORY_DEFAULT) to the intent filter, as follows: \n\n```\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n \n``` \n\n### Public Constructor Summary\n\n|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [ViewIntentBuilder](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder#ViewIntentBuilder(android.content.Context))([Context](//developer.android.com/reference/android/content/Context.html) context) |\n\n### Public Method Summary\n\n|------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Intent](//developer.android.com/reference/android/content/Intent.html) | [build](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder#build())() Returns the built intent, which can be used with [Context.startActivity(Intent)](//developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)) to launch the desired Fitness activity. |\n| [SessionsApi.ViewIntentBuilder](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder) | [setPreferredApplication](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder#setPreferredApplication(java.lang.String))([String](//developer.android.com/reference/java/lang/String.html) packageName) Sets a preferred application to use for this intent. |\n| [SessionsApi.ViewIntentBuilder](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder) | [setSession](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder#setSession(com.google.android.gms.fitness.data.Session))([Session](/android/reference/com/google/android/gms/fitness/data/Session) session) Sets the session to display data for. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Constructors\n-------------------\n\n#### public **ViewIntentBuilder** ([Context](//developer.android.com/reference/android/content/Context.html) context)\n\nPublic Methods\n--------------\n\n#### public [Intent](//developer.android.com/reference/android/content/Intent.html)\n**build** ()\n\nReturns the built intent, which can be used with [Context.startActivity(Intent)](//developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)) to launch the desired Fitness activity. \n\n##### Throws\n\n| [IllegalStateException](//developer.android.com/reference/java/lang/IllegalStateException.html) | If not enough data has been passed into the Builder to build a valid intent. |\n|-------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|\n\n#### public [SessionsApi.ViewIntentBuilder](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder)\n**setPreferredApplication** ([String](//developer.android.com/reference/java/lang/String.html) packageName)\n\nSets a preferred application to use for this intent. If the given app is installed\nand able to handle this intent, an explicit intent will be returned.\n\nBy default, the intent will attempt to use the application which inserted the\nsession. Use this method only to override that behavior. \n\n##### Parameters\n\n| packageName | The package name for the application to prefer for the intent, or `null` to not prefer any application |\n|-------------|--------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- This builder, for chaining. \n\n#### public [SessionsApi.ViewIntentBuilder](/android/reference/com/google/android/gms/fitness/SessionsApi.ViewIntentBuilder)\n**setSession** ([Session](/android/reference/com/google/android/gms/fitness/data/Session) session)\n\nSets the session to display data for. A specific session must be set. \n\n##### Parameters\n\n| session | The specific session to show data for. |\n|---------|----------------------------------------|\n\n##### Returns\n\n- This builder, for chaining."]]