public final class DisplayManager extends Object
Get an instance of this class by calling
Context.getSystemService()
with the argument
Context.DISPLAY_SERVICE
.
Modifier and Type | Class and Description |
---|---|
static interface |
DisplayManager.DisplayListener
Listens for changes in available display devices.
|
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_WIFI_DISPLAY_STATUS_CHANGED
Broadcast receiver that indicates when the Wifi display status changes.
|
static String |
DISPLAY_CATEGORY_PRESENTATION
Display category: Presentation displays.
|
static String |
EXTRA_WIFI_DISPLAY_STATUS
Contains a
WifiDisplayStatus object. |
static int |
VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
Virtual display flag: Allows content to be mirrored on private displays when no content is
being shown.
|
static int |
VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
Virtual display flag: Only show this display's own content; do not mirror
the content of another display.
|
static int |
VIRTUAL_DISPLAY_FLAG_PRESENTATION
Virtual display flag: Create a presentation display.
|
static int |
VIRTUAL_DISPLAY_FLAG_PUBLIC
Virtual display flag: Create a public display.
|
static int |
VIRTUAL_DISPLAY_FLAG_SECURE
Virtual display flag: Create a secure display.
|
Constructor and Description |
---|
DisplayManager(Context context) |
Modifier and Type | Method and Description |
---|---|
void |
connectWifiDisplay(String deviceAddress)
Connects to a Wifi display.
|
VirtualDisplay |
createVirtualDisplay(MediaProjection projection,
String name,
int width,
int height,
int densityDpi,
Surface surface,
int flags,
VirtualDisplay.Callback callback,
Handler handler) |
VirtualDisplay |
createVirtualDisplay(String name,
int width,
int height,
int densityDpi,
Surface surface,
int flags)
Creates a virtual display.
|
VirtualDisplay |
createVirtualDisplay(String name,
int width,
int height,
int densityDpi,
Surface surface,
int flags,
VirtualDisplay.Callback callback,
Handler handler)
Creates a virtual display.
|
void |
disconnectWifiDisplay()
Disconnects from the current Wifi display.
|
void |
forgetWifiDisplay(String deviceAddress)
Forgets a previously remembered Wifi display.
|
Display |
getDisplay(int displayId)
Gets information about a logical display.
|
Display[] |
getDisplays()
Gets all currently valid logical displays.
|
Display[] |
getDisplays(String category)
Gets all currently valid logical displays of the specified category.
|
WifiDisplayStatus |
getWifiDisplayStatus()
Gets the current Wifi display status.
|
void |
pauseWifiDisplay() |
void |
registerDisplayListener(DisplayManager.DisplayListener listener,
Handler handler)
Registers an display listener to receive notifications about when
displays are added, removed or changed.
|
void |
renameWifiDisplay(String deviceAddress,
String alias)
Renames a Wifi display.
|
void |
resumeWifiDisplay() |
void |
startWifiDisplayScan()
Starts scanning for available Wifi displays.
|
void |
stopWifiDisplayScan()
Stops scanning for available Wifi displays.
|
void |
unregisterDisplayListener(DisplayManager.DisplayListener listener)
Unregisters a display listener.
|
public static final String ACTION_WIFI_DISPLAY_STATUS_CHANGED
The status is provided as a WifiDisplayStatus
object in the
EXTRA_WIFI_DISPLAY_STATUS
extra.
This broadcast is only sent to registered receivers and can only be sent by the system.
public static final String EXTRA_WIFI_DISPLAY_STATUS
WifiDisplayStatus
object.public static final String DISPLAY_CATEGORY_PRESENTATION
This category can be used to identify secondary displays that are suitable for use as presentation displays such as HDMI or Wireless displays. Applications may automatically project their content to presentation displays to provide richer second screen experiences.
public static final int VIRTUAL_DISPLAY_FLAG_PUBLIC
When this flag is set, the virtual display is public.
A public virtual display behaves just like most any other display that is connected to the system such as an HDMI or Wireless display. Applications can open windows on the display and the system may mirror the contents of other displays onto it.
Creating a public virtual display that isn't restricted to own-content only implicitly
creates an auto-mirroring display. See VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
for
restrictions on who is allowed to create an auto-mirroring display.
When this flag is not set, the virtual display is private as defined by the
Display.FLAG_PRIVATE
display flag.
A private virtual display belongs to the application that created it. Only the a owner of a private virtual display is allowed to place windows upon it. The private virtual display also does not participate in display mirroring: it will neither receive mirrored content from another display nor allow its own content to be mirrored elsewhere. More precisely, the only processes that are allowed to enumerate or interact with the private display are those that have the same UID as the application that originally created the private virtual display.
public static final int VIRTUAL_DISPLAY_FLAG_PRESENTATION
When this flag is set, the virtual display is registered as a presentation
display in the presentation display category
.
Applications may automatically project their content to presentation displays
to provide richer second screen experiences.
When this flag is not set, the virtual display is not registered as a presentation display. Applications can still project their content on the display but they will typically not do so automatically. This option is appropriate for more special-purpose displays.
public static final int VIRTUAL_DISPLAY_FLAG_SECURE
When this flag is set, the virtual display is considered secure as defined
by the Display.FLAG_SECURE
display flag. The caller promises to take
reasonable measures, such as over-the-air encryption, to prevent the contents
of the display from being intercepted or recorded on a persistent medium.
Creating a secure virtual display requires the
android.Manifest.permission#CAPTURE_SECURE_VIDEO_OUTPUT
permission.
This permission is reserved for use by system components and is not available to
third-party applications.
When this flag is not set, the virtual display is considered unsecure. The content of secure windows will be blanked if shown on this display.
public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
This flag is used in conjunction with VIRTUAL_DISPLAY_FLAG_PUBLIC
.
Ordinarily public virtual displays will automatically mirror the content of the
default display if they have no windows of their own. When this flag is
specified, the virtual display will only ever show its own content and
will be blanked instead if it has no windows.
This flag is mutually exclusive with VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
. If both
flags are specified then the own-content only behavior will be applied.
This behavior of this flag is implied whenever neither VIRTUAL_DISPLAY_FLAG_PUBLIC
nor VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
have been set. This flag is only required to
override the default behavior when creating a public display.
public static final int VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
This flag is mutually exclusive with VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
.
If both flags are specified then the own-content only behavior will be applied.
The behavior of this flag is implied whenever VIRTUAL_DISPLAY_FLAG_PUBLIC
is set
and VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
has not been set. This flag is only
required to override the default behavior when creating a private display.
Creating an auto-mirroing virtual display requires the
android.Manifest.permission#CAPTURE_VIDEO_OUTPUT
or android.Manifest.permission#CAPTURE_SECURE_VIDEO_OUTPUT
permission.
These permissions are reserved for use by system components and are not available to
third-party applications.
Alternatively, an appropriate MediaProjection
may be used to create an
auto-mirroring virtual display.
public DisplayManager(Context context)
public Display getDisplay(int displayId)
displayId
- The logical display id.public Display[] getDisplays()
public Display[] getDisplays(String category)
When there are multiple displays in a category the returned displays are sorted
of preference. For example, if the requested category is
DISPLAY_CATEGORY_PRESENTATION
and there are multiple presentation displays
then the displays are sorted so that the first display in the returned array
is the most preferred presentation display. The application may simply
use the first display or allow the user to choose.
category
- The requested display category or null to return all displays.DISPLAY_CATEGORY_PRESENTATION
public void registerDisplayListener(DisplayManager.DisplayListener listener, Handler handler)
listener
- The listener to register.handler
- The handler on which the listener should be invoked, or null
if the listener should be invoked on the calling thread's looper.unregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener)
public void unregisterDisplayListener(DisplayManager.DisplayListener listener)
listener
- The listener to unregister.registerDisplayListener(android.hardware.display.DisplayManager.DisplayListener, android.os.Handler)
public void startWifiDisplayScan()
ACTION_WIFI_DISPLAY_STATUS_CHANGED
broadcast.
Calls to this method nest and must be matched by an equal number of calls to
stopWifiDisplayScan()
.
Requires android.Manifest.permission#CONFIGURE_WIFI_DISPLAY
.
public void stopWifiDisplayScan()
Requires android.Manifest.permission#CONFIGURE_WIFI_DISPLAY
.
public void connectWifiDisplay(String deviceAddress)
ACTION_WIFI_DISPLAY_STATUS_CHANGED
broadcast.
Automatically remembers the display after a successful connection, if not already remembered.
Requires android.Manifest.permission#CONFIGURE_WIFI_DISPLAY
.
deviceAddress
- The MAC address of the device to which we should connect.public void pauseWifiDisplay()
public void resumeWifiDisplay()
public void disconnectWifiDisplay()
ACTION_WIFI_DISPLAY_STATUS_CHANGED
broadcast.public void renameWifiDisplay(String deviceAddress, String alias)
The display must already be remembered for this call to succeed. In other words, we must already have successfully connected to the display at least once and then not forgotten it.
Requires android.Manifest.permission#CONFIGURE_WIFI_DISPLAY
.
deviceAddress
- The MAC address of the device to rename.alias
- The alias name by which to remember the device, or null
or empty if no alias should be used.public void forgetWifiDisplay(String deviceAddress)
Automatically disconnects from the display if currently connected to it.
Requires android.Manifest.permission#CONFIGURE_WIFI_DISPLAY
.
deviceAddress
- The MAC address of the device to forget.public WifiDisplayStatus getWifiDisplayStatus()
ACTION_WIFI_DISPLAY_STATUS_CHANGED
.public VirtualDisplay createVirtualDisplay(String name, int width, int height, int densityDpi, Surface surface, int flags)
public VirtualDisplay createVirtualDisplay(String name, int width, int height, int densityDpi, Surface surface, int flags, VirtualDisplay.Callback callback, Handler handler)
The content of a virtual display is rendered to a Surface
provided
by the application.
The virtual display should be released
when no longer needed. Because a virtual display renders to a surface
provided by the application, it will be released automatically when the
process terminates and all remaining windows on it will be forcibly removed.
The behavior of the virtual display depends on the flags that are provided to this method. By default, virtual displays are created to be private, non-presentation and unsecure. Permissions may be required to use certain flags.
As of Build.VERSION_CODES.KITKAT_WATCH
, the surface may
be attached or detached dynamically using VirtualDisplay.setSurface(android.view.Surface)
.
Previously, the surface had to be non-null when createVirtualDisplay(java.lang.String, int, int, int, android.view.Surface, int)
was called and could not be changed for the lifetime of the display.
Detaching the surface that backs a virtual display has a similar effect to turning off the screen.
name
- The name of the virtual display, must be non-empty.width
- The width of the virtual display in pixels, must be greater than 0.height
- The height of the virtual display in pixels, must be greater than 0.densityDpi
- The density of the virtual display in dpi, must be greater than 0.surface
- The surface to which the content of the virtual display should
be rendered, or null if there is none initially.flags
- A combination of virtual display flags:
VIRTUAL_DISPLAY_FLAG_PUBLIC
, VIRTUAL_DISPLAY_FLAG_PRESENTATION
,
VIRTUAL_DISPLAY_FLAG_SECURE
, VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
,
or VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
.callback
- Callback to call when the state of the VirtualDisplay
changeshandler
- The handler on which the listener should be invoked, or null
if the listener should be invoked on the calling thread's looper.SecurityException
- if the caller does not have permission to create
a virtual display with the specified flags.public VirtualDisplay createVirtualDisplay(MediaProjection projection, String name, int width, int height, int densityDpi, Surface surface, int flags, VirtualDisplay.Callback callback, Handler handler)