ProjectedContext
object 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 functions |
|
|---|---|
Context |
@RequiresApi(value = 34)Explicitly create the host device context from any context object. |
ActivityOptions |
@RequiresApi(value = 35)Creates |
Context |
@RequiresApi(value = 34)Explicitly create the Projected device context from any context object. |
String? |
@RequiresApi(value = 34)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. |
Flow<Boolean> |
@RequiresApi(value = 35)Observe whether a Projected device is connected to the host. |
Boolean |
@RequiresApi(value = 34)Returns whether the provided context is the Projected device context. |
Public functions
createHostDeviceContext
@RequiresApi(value = 34)
fun createHostDeviceContext(context: 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
@RequiresApi(value = 35)
fun createProjectedActivityOptions(context: Context): ActivityOptions
Creates ActivityOptions that should be used to start an activity on the Projected device.
| Parameters | |
|---|---|
context: Context |
any |
| Throws | |
|---|---|
kotlin.IllegalStateException |
if the projected display was not found or if the Projected device doesn't have any displays. |
createProjectedDeviceContext
@RequiresApi(value = 34)
fun createProjectedDeviceContext(context: Context): Context
Explicitly create the Projected device context from any context object.
| Throws | |
|---|---|
kotlin.IllegalStateException |
if the projected device was not found. |
getProjectedDeviceName
@RequiresApi(value = 34)
fun getProjectedDeviceName(context: Context): 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.
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
If another context is used (e.g. the host context). |
isProjectedDeviceConnected
@RequiresApi(value = 35)
fun isProjectedDeviceConnected(
context: Context,
coroutineContext: CoroutineContext
): Flow<Boolean>
Observe whether a Projected device is connected to the host.
| Parameters | |
|---|---|
context: Context |
The context used to access the |
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
@RequiresApi(value = 34)
fun isProjectedDeviceContext(context: Context): Boolean
Returns whether the provided context is the Projected device context.