Detect if samsung Dex is On when external display not connected

Is there a way to detect if Samsung dex is on/ HDMI mode is set to “Samsung dex”? I tried using following dex API but it only works if my s22 is connected to an external display. I want to be able to detect if dex is turned on/off even when phone is not connected to an external display. In another words, I want to check if HDMI mode is set to “Screen Mirroring” or “Samung dex”.

public static boolean IsDeXEnabled(Activity unityActivity) {
Object desktopModeManager = unityActivity.getApplicationContext().getSystemService(“desktopmode”);
if (desktopModeManager != null) {
try {
Method getDesktopModeStateMethod = desktopModeManager.getClass().getDeclaredMethod(“getDesktopModeState”);
Object desktopModeState = getDesktopModeStateMethod.invoke(desktopModeManager);
Class desktopModeStateClass = desktopModeState.getClass();
Method getEnabledMethod = desktopModeStateClass.getDeclaredMethod(“getEnabled”);
int enabled = (int) getEnabledMethod.invoke(desktopModeState);
boolean isEnabled = enabled == desktopModeStateClass.getDeclaredField(“ENABLED”).getInt(desktopModeStateClass);

            Method getDisplayTypeMethod = desktopModeStateClass.getDeclaredMethod("getDisplayType");
            int displayType = (int) getDisplayTypeMethod.invoke(desktopModeState);
            return isEnabled && displayType == desktopModeStateClass.getDeclaredField("DISPLAY_TYPE_DUAL").getInt(desktopModeStateClass);

        } catch (NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            // Device does not support DeX 3.0
            return false;
    return false;

I am developing an app which uses a secondary display connected via USB-C but if user accidently turns dex on or changes HDMI mode to “Samsung dex” external display turns off. i want to show user a warning that Dex is turned on and ask to disable it or change HDMI mode to “screen mirroring” for app to work

Try GitHub for Dex Discussions I haven’t seen much discussion on this Samsung community in years.

Samsung Developer Relations