How do I enable and disable DeX display?

Use the following API:

  • DexManager.setDexDisabled(): to disable (true) or enable (false) DeX display, either through USB or wirelessly, either inside or outside a work profile.

Here is some sample source code to disable all USB interfaces except HID devices like mice and keyboards, and Samsung DeX:

EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
DexManager dexMgr = edm.getDexManager();

For information about enabling and disabling USB connections, see How do I specify how a device USB can be used?