ProjectedContext


public static class ProjectedContext


Helper for accessing Projected device Context and its features.

Projected device is an XR device connected to an Android device (host). Host can project the application content to the Projected device and let users interact with it.

The Projected device context will ensure Projected device system services are returned, when queried for system services from this object.

Note: The application context's deviceId can switch between the Projected and host deviceId depending on which activity was most recently in the foreground. Prefer using the Activity context to minimize the risk of running into this problem.

Summary

Public fields

static @NonNull ProjectedContext

Public methods

static final @NonNull Context

Explicitly create the host device context from any context object.

static final @NonNull ActivityOptions

Creates ActivityOptions that should be used to start an activity on the Projected device.

static final @NonNull Context

Explicitly create the Projected device context from any context object.

static final String

Returns the name of the Projected device or null if either virtual device wasn't found or the name of the virtual device wasn't set.

static final @NonNull Flow<@NonNull Boolean>
@RequiresApi(value = 35)
isProjectedDeviceConnected(
    @NonNull Context context,
    @NonNull CoroutineContext coroutineContext
)

Observe whether a Projected device is connected to the host.

static final boolean

Returns whether the provided context is the Projected device context.

Public fields

INSTANCE

Added in 1.0.0-alpha01
public static @NonNull ProjectedContext INSTANCE

Public methods

createHostDeviceContext

Added in 1.0.0-alpha01
@RequiresApi(value = 34)
public static final @NonNull Context createHostDeviceContext(@NonNull Context context)

Explicitly create the host device context from any context object. The host is the device that connects to a Projected device.

If an application is using a Projected device context and it wants to use system services from the host (e.g. phone), it needs to use the host device context.

createProjectedActivityOptions

Added in 1.0.0-alpha01
@RequiresApi(value = 35)
public static final @NonNull ActivityOptions createProjectedActivityOptions(@NonNull Context context)

Creates ActivityOptions that should be used to start an activity on the Projected device.

Parameters
@NonNull Context context

any Context object. If the provided context is not a Projected device context, a Projected device context will be created automatically and used to create Projected ActivityOptions.

Throws
kotlin.IllegalStateException

if the projected display was not found or if the Projected device doesn't have any displays.

createProjectedDeviceContext

Added in 1.0.0-alpha01
@RequiresApi(value = 34)
public static final @NonNull Context createProjectedDeviceContext(@NonNull Context context)

Explicitly create the Projected device context from any context object.

Throws
kotlin.IllegalStateException

if the projected device was not found.

getProjectedDeviceName

Added in 1.0.0-alpha01
@RequiresApi(value = 34)
public static final String getProjectedDeviceName(@NonNull Context context)

Returns the name of the Projected device or null if either virtual device wasn't found or the name of the virtual device wasn't set.

Throws
kotlin.IllegalArgumentException

If another context is used (e.g. the host context).

isProjectedDeviceConnected

Added in 1.0.0-alpha01
@RequiresApi(value = 35)
public static final @NonNull Flow<@NonNull BooleanisProjectedDeviceConnected(
    @NonNull Context context,
    @NonNull CoroutineContext coroutineContext
)

Observe whether a Projected device is connected to the host.

Parameters
@NonNull Context context

The context used to access the VirtualDeviceManager. It can be any context object.

@NonNull CoroutineContext coroutineContext

The CoroutineContext that includes CoroutineDispatcher which is where the Projected device connectivity observer is executed on.

Throws
kotlin.IllegalArgumentException

if provided coroutineContext doesn't include CoroutineDispatcher.

isProjectedDeviceContext

Added in 1.0.0-alpha01
@RequiresApi(value = 34)
public static final boolean isProjectedDeviceContext(@NonNull Context context)

Returns whether the provided context is the Projected device context.