YouTube

YouTubeIntents

public final class
YouTubeIntents
java.lang.Object
   ↳ com.google.android.youtube.player.YouTubeIntents

Overview

A selection of static methods that create intents which navigate to specific activities within the main YouTube application.

Video and playlist IDs required by methods such as createPlayVideoIntent(Context, String) or createOpenPlaylistIntent(Context, String) are provided by the YouTube Data API. To learn more about this API, visit https://developers.google.com/youtube/.

Use the canResolve methods before sending an intent to make sure that the user's device has a version of the YouTube application which supports the given intent.

Summary

Public methods
static boolean canResolveOpenPlaylistIntent(Context context)
Checks if the YouTube application installed on the user's device supports the open playlist intent.
static boolean canResolvePlayPlaylistIntent(Context context)
Checks if the YouTube application installed on the user's device supports the play playlist intent.
static boolean canResolvePlayVideoIntent(Context context)
Checks if the YouTube application installed on the user's device supports the play video intent.
static boolean canResolveSearchIntent(Context context)
Checks if the YouTube application installed on the user's device supports the open search results intent.
static boolean canResolveUploadIntent(Context context)
Checks if the YouTube application installed on the user's device supports the upload video intent.
static boolean canResolveUserIntent(Context context)
Checks if the YouTube application installed on the user's device supports the open user intent.
static Intent createOpenPlaylistIntent(Context context, String playlistId)
Creates an Intent that, when resolved, will open the given playlist in the YouTube application.
static Intent createPlayPlaylistIntent(Context context, String playlistId)
Creates an Intent that, when resolved, will start playing the given playlist in the YouTube application from its first video.
static Intent createPlayVideoIntent(Context context, String videoId)
Creates an Intent that, when resolved, will start playing the video specified by videoId, within the YouTube application.
static Intent createPlayVideoIntentWithOptions(Context context, String videoId, boolean fullscreen, boolean finishOnEnd)
Creates an Intent that, when resolved, will start playing the video specified by videoId, within the YouTube application.
static Intent createSearchIntent(Context context, String query)
Creates an Intent that, when resolved, will open the search results for the given query in the YouTube application.
static Intent createUploadIntent(Context context, Uri videoUri)
Creates an Intent that, when resolved, will open the upload activity in the YouTube application for the video specified by the videoUri.
static Intent createUserIntent(Context context, String username)
Creates an Intent that, when resolved, will open the user page for the given user ID in the YouTube application.
static int getInstalledYouTubeVersionCode(Context context)
Retrieves the version code of the YouTube application installed on the user's device.
static String getInstalledYouTubeVersionName(Context context)
Retrieves the version name of the YouTube application installed on the user's device.
static boolean isYouTubeInstalled(Context context)
Checks if the YouTube application is installed on the user's device.
[Expand]
Inherited methods
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)

Public methods

public static boolean canResolveOpenPlaylistIntent (Context context)

Checks if the YouTube application installed on the user's device supports the open playlist intent.

Parameters
context The current Context.
Returns
  • true if the YouTube application installed on the user's device allows external apps to navigate to the Playlist page, false otherwise.

public static boolean canResolvePlayPlaylistIntent (Context context)

Checks if the YouTube application installed on the user's device supports the play playlist intent.

Parameters
context The current Context.
Returns
  • true if the YouTube application installed on the user's device allows external apps to start playing a playlist, false otherwise.

public static boolean canResolvePlayVideoIntent (Context context)

Checks if the YouTube application installed on the user's device supports the play video intent.

Parameters
context The current Context.
Returns
  • true if the YouTube application installed on the user's device allows external apps to play a video in the YouTube application, false otherwise.

public static boolean canResolveSearchIntent (Context context)

Checks if the YouTube application installed on the user's device supports the open search results intent.

Parameters
context The current Context.
Returns
  • true if the YouTube application installed on the user's device allows external apps to perform a search, false otherwise.

public static boolean canResolveUploadIntent (Context context)

Checks if the YouTube application installed on the user's device supports the upload video intent.

Parameters
context The current Context.
Returns
  • true if the YouTube application installed on the user's device allows external apps to upload videos to YouTube, false otherwise.

public static boolean canResolveUserIntent (Context context)

Checks if the YouTube application installed on the user's device supports the open user intent.

Parameters
context The current Context.
Returns
  • true if the YouTube application installed on the user's device allows external apps to navigate to the User page, false otherwise.

public static Intent createOpenPlaylistIntent (Context context, String playlistId)

Creates an Intent that, when resolved, will open the given playlist in the YouTube application.

Parameters
context The current Context.
playlistId The ID of the playlist to be opened, as returned from the YouTube Data API.
Returns
  • An intent that will open the Playlist page in the YouTube app with the given playlist.

public static Intent createPlayPlaylistIntent (Context context, String playlistId)

Creates an Intent that, when resolved, will start playing the given playlist in the YouTube application from its first video.

Parameters
context The current Context.
playlistId The ID of the playlist to be played, as returned from the YouTube Data API.
Returns
  • An intent that will play the given playlist in the YouTube app.

public static Intent createPlayVideoIntent (Context context, String videoId)

Creates an Intent that, when resolved, will start playing the video specified by videoId, within the YouTube application.

Parameters
context The current Context.
videoId The ID of the video to be played, as returned from the YouTube Data API.
Returns
  • An Intent which will start playing the video in the YouTube application.

public static Intent createPlayVideoIntentWithOptions (Context context, String videoId, boolean fullscreen, boolean finishOnEnd)

Creates an Intent that, when resolved, will start playing the video specified by videoId, within the YouTube application.

Parameters
context The current Context.
videoId The ID of the video to be played, as returned from the YouTube Data API.
fullscreen If true the video will be played fullscreen, if false the video will be played according to the orientation of the device.
finishOnEnd If true will finish the YouTube application activity and return to the calling activity once the video has finished, if false will only return when the user presses back.
Returns
  • An Intent which will start playing the video.

public static Intent createSearchIntent (Context context, String query)

Creates an Intent that, when resolved, will open the search results for the given query in the YouTube application.

Parameters
context The current Context.
query The search query to request search results for.
Returns
  • An Intent that will open the search results page in the YouTube app with the results for the given query.

public static Intent createUploadIntent (Context context, Uri videoUri)

Creates an Intent that, when resolved, will open the upload activity in the YouTube application for the video specified by the videoUri. An exception will be thrown if videoUri does not exist or is invalid. If the video specified by videoUri does not exist, the resulting Activity will end immediately after starting.

Parameters
context The current Context.
videoUri A Uri that points to the video on your device you wish to upload.
Returns
  • An Intent that will open the upload page in the YouTube app, with the specified video already selected for loaded.
Throws
IllegalArgumentException will be thrown if the video specified by the Uri is invalid.

public static Intent createUserIntent (Context context, String username)

Creates an Intent that, when resolved, will open the user page for the given user ID in the YouTube application.

Parameters
context The current Context.
username The name of the channel that you want to retrieve information about.
Returns
  • An Intent that will open the given users' page in the YouTube app.

public static int getInstalledYouTubeVersionCode (Context context)

Retrieves the version code of the YouTube application installed on the user's device. This call will return -1 if YouTube has not been installed.

Parameters
context The current Context.
Returns
  • A string representation of the version of YouTube installed on this device. -1 if YouTube is not installed.

public static String getInstalledYouTubeVersionName (Context context)

Retrieves the version name of the YouTube application installed on the user's device. This call will return null if YouTube has not been installed.

Parameters
context The current Context.
Returns
  • A string representation of the version of YouTube installed on this device. null if YouTube is not installed.

public static boolean isYouTubeInstalled (Context context)

Checks if the YouTube application is installed on the user's device.

Parameters
context The current Context.
Returns
  • true if the YouTube application is installed on the user's device, false otherwise.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.