Skip to main content
Samsung Developer Program

Develop

This section provides an overview of how to modify apps to launch in Samsung DeX. Because of code variance from app to app, not all use cases may be covered. Additional Android resources may be required for specific apps to work.

To work with Samsung DeX, apps must support Android N multi-window mode. Multi-window support allows apps to be resized dynamically in Samsung DeX. For more information on implementing multi-window mode, see https://developer.android.com/guide/...ti-window.html.

No new Samsung APIs need to be used to launch apps in Samsung DeX. However, apps must adhere to Android N multi-window standards in order to open in desktop mode. Desktop mode includes all of the advanced, multitasking features built in to the Samsung DeX UI. 

Samsung DeX App Modification Checklist

The Samsung DeX app modification process is as follows:

  • Determine app requirements: For example, determine whether you want a fixed-size or resizable window.

  • Implement code modifications: Follow the mandatory requirements.

  • Test the app in Samsung DeX: Use the Android virtual emulator (see the Samsung DeX App Testing Guide).

App Modification Requirements

Category Feature
Mandatory requirements 
  • Multi-Density (640 dpi, 160 dpi)
  • Faketouch support (mouse or touchpad)
Mandatory requirements
(desktop mode)
  • Android N multi-window mode (explicitly declare android:resizableActivity="true")
  • Seven runtime configuration changes made through the Keepalive declaration in the Manifest
Optional compatibility features
  • Optimized Samsung internet browser
  • Mouse right-click
  • Mouse-wheel zoom
  • Mouse icon change
  • Mouse app scroll bar
  • Keyboard shortcuts
  • Drag and drop
  • Disable presentation class
  • Disable fixed orientation for camera

Mandatory Requirements

To open in fixed-size window mode, apps must:

  • Support multi-density for xxxhdpi (640 dpi) and mdpi (160 dpi)
  • Support mouse or trackpad interaction
Multi-Density Support

Multi-density support involves configuring apps with different resources so they can adapt to different screen sizes and resolutions. Samsung DeX-compatible apps must be able to handle both xxxhdpi (640 dpi) and mdpi (160 dpi) resolutions to ensure that apps can be rendered both in mobile (xxxhdpi) and Samsung DeX (mdpi). This may include adjustments, such as ensuring that:

  • Layouts are resized to fit Samsung DeX screen resolution.

  • Images scale properly to Samsung DeX screen resolution.

  • The correct UI appears in Samsung DeX, according to new screen configurations.

For more information, see Android best practices for supporting different densities and screen sizes (https://developer.android.com/guide/...s_support.html).

TIP: Building a responsive layout from the ground up helps ensure that your app provides the best user experience. Consider using a preexisting tablet UI as a starting point for layouts in different resolutions.

 

Examples: Types of Changes Necessary Support Multi-Density

The following example shows how an app declares different densities in the manifest.

  • Pixel density: Use dp rather than px to ensure that layouts scale properly. For example, the following code shows an example of using dp in the manifest:
<TextView
    android:id="@+id/title"
    android:layout_marginTop="20dp"
    android:text="@string/title"/>
  • Image assets: Ensure appropriate image assets exist for different resolutions. For example, the following image shows the asset folders with different images for mdpi and xxxhdpi:

    Figure 2: Mobile mode VS Desktop mode
Mouse or Trackpad Interaction Support

Apps must not declare that touchscreen or multi-touch mode is required in the manifest. This disallows apps from using a mouse in Samsung DeX. Apps should not block faketouch input; otherwise, users cannot use apps with a mouse or touchpad.

 

Keyboard and Mouse

Ideally, apps should support a Bluetooth or USB keyboard and mouse. If an app has issues with mouse and keyboard support in Samsung DeX, ensure the mouse and keyboard are not explicitly disabled. In the manifest, check that these two statements are not declared:

  • <uses-configuration android:reqTouchScreen="finger">

  • <uses-feature android:name="android.hardware.touchscreen" android:required="true">

For details on avoiding explicit declaration of touchscreen, see the Android uses-configuration and uses-feature APIs:

 

Mandatory Requirements (Desktop Mode)

Apps must meet these mandatory requirements to open in desktop mode:

  • Apps must support Android N multi-window mode and explicitly declare android:resizableActivity="true" in the manifest.
  • An app must support seven runtime configuration changes and explicitly declare that it meets these conditions in the manifest with the following:<meta-data android:name="com.samsung.android.keepalive.density" android:value="true"/>

 

Android N Multi-Window Support

Apps must support Android N multi-window mode. Multi-window support allows apps to be resized dynamically in Samsung DeX. For more information on implementing multi-window mode, see the Android multi-window support guide (https://developer.android.com/guide/...ti-window.html).

Multi-window mode is built on top of Android's preexisting resource system, in which apps can provide multiple resources to change how they appear (e.g., layouts, menus). Multi-window mode uses these resources to adjust app configurations based on the size of the display window. This allow apps to be resized in free-form, just as on a desktop (for more information, see https://developer.android.com/guide/...ativeResources).

Note: If an app launches an activity in another app, the subsequent app must also support multi-window mode. Activities that can be started by other apps will inherit the same multi-window properties as the calling activity (for more information, see https://developer.android.com/guide/....html?#running). 

 

Implement Multi-Window Support in Samsung DeX

SDK 24 and higher: Apps targeting SDK 24 and higher support multi-window as a native feature by default. However, apps operating in Samsung DeX desktop mode still must explicitly enable multi-window mode in the manifest to be run in a resizable window.

To enable multi-window support for Samsung DeX, paste this code into the manifest:

<application
    android:resizeableActivity="true">
</application>
Runtime Configuration Changes

Apps must support the following seven runtime configuration changes:

  • Density change between xxxhdpi and mdpi

  • Resolution change between WQHD and FHD

  • Orientation change between portrait to landscape

  • Screen layout change

  • Screen size change

  • Smallest screen size change

  • UI mode change between mobile and desktop

Runtime configuration changes are important in Android, because they are the underlying framework that reloads resources when certain actions are performed. This can include changing the default language or rotating your device.

In Samsung DeX, a configuration change occurs every time the device is placed into the Samsung DeX station. If configuration changes are not handled properly, the app will not load correctly when it appears on the monitor. For example, if a full-screen video is playing when the device is plugged into the DeX Station, it should not restart back to the beginning, change orientation, or exit full screen when cast to the monitor. The transition should be seamless. For full details on handling runtime changes, see Android's page on runtime changes (https://developer.android.com/guide/...e-changes.html).

 

Samsung DeX Runtime Changes

By default, apps are closed automatically when they switch between mobile mode and Samsung DeX. However, some exceptions exist, such as preloaded Samsung apps. To ensure your app is not closed automatically upon launching in Samsung DeX, change the following Android runtimes to match configuration standards:

  • ORIENTATION
  • SCREEN_LAYOUT
  • SCREEN_SIZE
  • SMALLEST_SCREEN_SIZE

The image below shows an example of configuration changes that may be required:

In the example, configuration changes are handled dynamically by adding theandroid:configChangesflag to the activity's manifest. Note that the actual implementation of the configuration changes will vary from app to app, depending on what type of content is being used. For information about configuration changes, see Android's section on resizing tasks and windows (https://developer.android.com/topic/...html#resizable).

 

Keepalive Declaration

If an app can handle the seven runtime changes described above and operate in Samsung DeX without issues, it must declare the following keepalive declaration in the manifest:

<application>
    <meta-data android:name="com.samsung.android.keepalive.density" android:value="true"/>
</application>

This manifest declaration identifies to Samsung DeX that an app has been tested, runs properly, and prevents Samsung DeX from automatically closing the app when switching between views. 

keepalive declaration in Manifest App status before switching App status before switching
Yes Foreground
Background
Alive
Alive
No Foreground
Background
Stopped and restarted
Closed

 

Detect Samsung DeX Mode

When the display mode changes from mobile to Samsung DeX mode, its configuration changes. Use the system configurations described below to detect Samsung DeX mode:

  • UI mode: desk

  • Screen layout: xlarge

  • UI mode: desk

  • Density: mdpi

  • Resolution: FHD

  • Orientation: portrait to landscape

The following code sample shows how third-party apps can query DeX current status:

import android.content.res.Configuration;
import java.lang.reflect.Field;
import java.lang.Class;

Configuration config = getResources().getConfiguration();
      try {
          Class configClass = config.getClass();
          if(configClass.getField("SEM_DESKTOP_MODE_ENABLED").getInt(configClass)
          == configClass.getField("semDesktopModeEnabled").getInt(config)) {

          // Samsung DeX mode enabled
         }
      } catch(NoSuchFieldException e) {
      } catch(IllegalAccessException e) {
      } catch(IllegalArgumentException e) {
      }

Optional Compatibility Features

For the best desktop experience, apps should have these optional compatibility features. 

Optimized Samsung Internet Browser

To provide a desktop experience with the Samsung internet browser, follow these steps:

  1. Open web pages in desktop view instead of mobile view.

    Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) 
    SamsungBrowser/$app_ver Chrome/$engine_ver Safari/537.36 
    ※ Current values: app_ver = 5.2 , engine_ver = 51.0.2704.106
    
    • User Agent String for Samsung internet desktop view: based on Chrome Linux UA with additional SamsungBrowser/$app_ver keyword.

  2. Allow users to switch to mobile when needed.

    Mozilla/5.0 (Linux; Android $ver; $model) AppleWebKit/537.36 (KHTML, like Gecko)
    SamsungBrowser/$app_ver Chrome/$engine_ver Mobile Safari/537.36
    ※ Current values: android_ver = 7.0 app_ver = 5.2 , engine_ver = 51.0.2704.106\
    • User agent string for Samsung internet mobile view.

  3. Support mouse events.

    • In Samsung DeX mode, mouse events are processed as mouse events (in mobile mode, mouse events are processed as touch events). However, because Touchpad is a supported input device in Samsung DeX, touch events are also supported.

    • Removing mouse event listeners on touch supported browsers might limit mouse usage on your web site.

  4. Support auto-play.

    <video width="320" height="240" controls autoplay> <source src="movie.ogg" type="video/ogg">
    • The HTML < video > autoplay attribute works in desktop mode (not supported in mobile mode).

Mouse Right-Click

Enabling the mouse right-click function allows for easier interaction with apps, such as opening a contextual menu on the desktop.

If an app uses the Google API EditTextView, it does not need additional implementation for using mouse right-click. The following actions are available in EditTextview:

  • Mouse right-click: show contextual menu.
  • Mouse left-double click on text: select the text.

If an app is not using EditTextView, use the following code snippet to enable the mouse right-click function.

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  layout_main = (RelativeLayout) findViewById(R.id.layout_main);
  registerForContextMenu(layout_main);
}

@Override
public void onCreateContextMenu(ContextMenu menu,
                    View v, ContextMenu.ContextMenuInfo menuInfo){
  if (v.getId() == R.id.layout_main) {
	  menu.setHeaderTitle("Context Menu Test");
	  menu.add(Menu.NONE, ONE, Menu.NONE, "Menu 1");
  }
  super.onCreateContextMenu(menu, v, menuInfo);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
  if (event.getAction() == MotionEvent.ACTION_DOWN &&
	   event.getButtonState() == MotionEvent.BUTTON_SECONDARY) {

	  layout_main.showContextMenu(event.getX(), event.getY());
  }
  return super.onTouchEvent(event);
}
Mouse-Wheel Zoom

Enabling mouse-wheel zoom allows for easier interaction with apps such as games and maps that require multi-touch zoom (pinch zoom in and out) to operate efficiently. To enable multi-touch, an app must receive the wheel up/down eventMotionEvent.ACTION_SCROLL in Activity.dispatchTouchEvent(MotionEvent event) and apply the pinch-zoom function of the app with step-by-step information of the wheel scroll.

For example:final float vScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
- vScroll is -1.0, wheel down.
- vScroll is 1.0, wheel up.

@Override public boolean onGenericMotion(View v, MotionEvent event) {
	int action = event.getAction();
	int actionCode = action & MotionEvent.ACTION MASK;

	for (int i = 0; i < event.getPointerCount(); i++) {
		float x = event.getX(i);
		float y = event.getY(i);
		float p = event.getPressure(i);
		int pid = event.getPointerld(i);

		if (actionCode == MotionEvent.ACTION_SCROLL) {
			float wheelX = event.getAxisValue(MotionEvent.AXIS_HSCROLL, i);
			float wheelY = event.getAxisValue(MotionEvent.AXIS_VSCROLL, i);
			SOLMain.mcNativeTouch(actionCode, wheelX, wheelY, p, pid);

			return true;
		}
	}
}
Mouse Icon Change

This allows the mouse icon to change when pointed at a clickable object. To change the mouse icon, set android:state_hovered="true" on the required views.

App/res/drawable/tw_list_selector_material_light.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_hovered="true" android:state_finger_hovered="true">
      <nine-patch android:src="@drawable/tw_list_hover_holo_light" />
    </item>

For more information, see the following:

 

Mouse App Scroll Bar

Mouse scrolling works automatically if apps use the Google SDK ListView, GridView, or ScrollView / HorizontalScrollView (see https://developer.android.com/refere...crollView.html).

Keyboard Shortcuts

Keyboard shortcuts provide enhanced multi-tasking usability in apps (see https://developer.android.com/traini.../commands.html).

Drag and Drop

The drag-and-drop function allows you to move files easily between views. For more information, see the following:

Disable Presentation Class in Samsung DeX

Presentation class allows an app to show content on a secondary display. This may not be ideal for Samsung DeX apps and can be disabled if needed (see https://developer.android.com/refere...sentation.html).

Disable Fixed Orientation for Camera

If an app requires fixed orientation for camera use, it may not translate well to Samsung DeX Desktop mode. Fixed orientation for camera can be disabled, if needed (see https://developer.android.com/refere...e-summary.html).

 

 

  • Was this article helpful?