# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Ctors | Methods | Inherited Methods

# MediaSession2.SessionCallback

`public static abstract class MediaSession2.SessionCallback`
`extends Object` ``

java.lang.Object
↳ | android.media.MediaSession2.SessionCallback

This API is not generally intended for third party application developers. Use the AndroidX Media2 session Library for consistent behavior across all devices.

Callback to be called for all incoming commands from `MediaController2`s.

## Summary

### Public constructors
`SessionCallback()`

### Public methods
`void` | `onCommandResult(MediaSession2 session, MediaSession2.ControllerInfo controller, Object token, Session2Command command, Session2Command.Result result)` Called when the command sent to the controller is finished.
`Session2CommandGroup` | `onConnect(MediaSession2 session, MediaSession2.ControllerInfo controller)` Called when a controller is created for this session.
`void` | `onDisconnected(MediaSession2 session, MediaSession2.ControllerInfo controller)` Called when a controller is disconnected
`void` | `onPostConnect(MediaSession2 session, MediaSession2.ControllerInfo controller)` Called immediately after a controller is connected.
`Session2Command.Result` | `onSessionCommand(MediaSession2 session, MediaSession2.ControllerInfo controller, Session2Command command, Bundle args)` Called when a controller sent a session command.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.

## Public constructors

### SessionCallback

    public SessionCallback ()

## Public methods

### onCommandResult

    public void onCommandResult (MediaSession2 session,
                    MediaSession2.ControllerInfo controller,
                    Object token,
                    Session2Command command,
                    Session2Command.Result result)

Called when the command sent to the controller is finished.

Parameters
`session` | `MediaSession2`: the session for this event This value cannot be `null`.
`controller` | `MediaSession2.ControllerInfo`: controller information This value cannot be `null`.
`token` | `Object`: the token got from `MediaSession2#sendSessionCommand` This value cannot be `null`.
`command` | `Session2Command`: the session command This value cannot be `null`.
`result` | `Session2Command.Result`: the result of the session command This value cannot be `null`.

### onConnect

    public Session2CommandGroup onConnect (MediaSession2 session,
                    MediaSession2.ControllerInfo controller)

Called when a controller is created for this session. Return allowed commands for controller. By default it returns `null`.

You can reject the connection by returning `null`. In that case, controller receives `MediaController2.ControllerCallback#onDisconnected(MediaController2)` and cannot be used.

The controller hasn't connected yet in this method, so calls to the controller (e.g. `MediaSession2.sendSessionCommand(MediaSession2.ControllerInfo, Session2Command, Bundle)`) would be ignored. Override `onPostConnect(MediaSession2, MediaSession2.ControllerInfo)` for the custom initialization for the controller instead.

Parameters
`session` | `MediaSession2`: the session for this event This value cannot be `null`.
`controller` | `MediaSession2.ControllerInfo`: controller information. This value cannot be `null`.

Returns
`Session2CommandGroup` | allowed commands. Can be `null` to reject connection.

### onDisconnected

    public void onDisconnected (MediaSession2 session,
                    MediaSession2.ControllerInfo controller)

Called when a controller is disconnected

Parameters
`session` | `MediaSession2`: the session for this event This value cannot be `null`.
`controller` | `MediaSession2.ControllerInfo`: controller information This value cannot be `null`.

### onPostConnect

    public void onPostConnect (MediaSession2 session,
                    MediaSession2.ControllerInfo controller)

Called immediately after a controller is connected. This is a convenient method to add custom initialization between the session and a controller.

Note that calls to the controller (e.g. `MediaSession2.sendSessionCommand(MediaSession2.ControllerInfo, Session2Command, Bundle)`) work here but don't work in `onConnect(MediaSession2, MediaSession2.ControllerInfo)` because the controller hasn't connected yet in `onConnect(MediaSession2, MediaSession2.ControllerInfo)`.

Parameters
`session` | `MediaSession2`: the session for this event This value cannot be `null`.
`controller` | `MediaSession2.ControllerInfo`: controller information. This value cannot be `null`.

### onSessionCommand

    public Session2Command.Result onSessionCommand (MediaSession2 session,
                    MediaSession2.ControllerInfo controller,
                    Session2Command command,
                    Bundle args)

Called when a controller sent a session command.

Parameters
`session` | `MediaSession2`: the session for this event This value cannot be `null`.
`controller` | `MediaSession2.ControllerInfo`: controller information This value cannot be `null`.
`command` | `Session2Command`: the session command This value cannot be `null`.
`args` | `Bundle`: optional arguments This value may be `null`.

Returns
`Session2Command.Result` | the result for the session command. If `null`, RESULT_INFO_SKIPPED will be sent to the session.

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*