VirtualDeviceManager


public final class VirtualDeviceManager
extends Object

java.lang.Object
   ↳ android.companion.virtual.VirtualDeviceManager


System level service for creation and management of virtual devices.

VirtualDeviceManager enables interactive sharing of capabilities between the host Android device and a remote device.

Not to be confused with the Android Studio's Virtual Device Manager, which allows for device emulation.

Summary

Nested classes

interface VirtualDeviceManager.VirtualDeviceListener

Listener for changes in the available virtual devices. 

Public methods

VirtualDevice getVirtualDevice(int deviceId)

Returns the details of the virtual device with the given ID, if any.

List<VirtualDevice> getVirtualDevices()

Returns the details of all available virtual devices.

void registerVirtualDeviceListener(Executor executor, VirtualDeviceManager.VirtualDeviceListener listener)

Registers a virtual device listener to receive notifications when virtual devices are created or closed.

void unregisterVirtualDeviceListener(VirtualDeviceManager.VirtualDeviceListener listener)

Unregisters a virtual device listener previously registered with registerVirtualDeviceListener(Executor, VirtualDeviceListener).

Inherited methods

Public methods

getVirtualDevice

Added in API level 35
public VirtualDevice getVirtualDevice (int deviceId)

Returns the details of the virtual device with the given ID, if any.

The returned object is a read-only representation of the virtual device that expose its properties.

Note that if the virtual device is closed and becomes invalid, the returned object will not be updated and may contain stale values. Use a VirtualDeviceListener for real time updates of the availability of virtual devices.

Parameters
deviceId int

Returns
VirtualDevice the virtual device with the requested ID, or null if no such device exists or it has already been closed.

getVirtualDevices

Added in API level 34
public List<VirtualDevice> getVirtualDevices ()

Returns the details of all available virtual devices.

The returned objects are read-only representations that expose the properties of all existing virtual devices.

Note that if a virtual device is closed and becomes invalid, the returned objects will not be updated and may contain stale values.

Returns
List<VirtualDevice> This value cannot be null.

registerVirtualDeviceListener

Added in API level 35
public void registerVirtualDeviceListener (Executor executor, 
                VirtualDeviceManager.VirtualDeviceListener listener)

Registers a virtual device listener to receive notifications when virtual devices are created or closed.

Parameters
executor Executor: The executor where the listener is executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

listener VirtualDeviceManager.VirtualDeviceListener: The listener to add. This value cannot be null.

unregisterVirtualDeviceListener

Added in API level 35
public void unregisterVirtualDeviceListener (VirtualDeviceManager.VirtualDeviceListener listener)

Unregisters a virtual device listener previously registered with registerVirtualDeviceListener(Executor, VirtualDeviceListener).

Parameters
listener VirtualDeviceManager.VirtualDeviceListener: The listener to unregister. This value cannot be null.