[Samsung DeX] Optimization of VNC client for Samsung DeX

Samsung Developer Program

As you know, in late March, at the same time with the new flagship, Samsung introduced a new product - DeX station for Galaxy S8/S8+. It is designed to give a desktop experience for you Smartphone with the help of a special mode.

This mode is activated when the Smartphone is placed in DeX station. Also you will need a mouse, a keyboard and a monitor connected via HDMI. Besides all of this, it is necessary the application have to support the new mode. A number of popular apps in the Play Store already did it.

In order for your application to allow the user to get the Desktop Experience, you must follow a several simple recommendations presented on the Samsung developers portal: https://developer.samsung.com/samsung-dex/modify-optimizing.html

To demonstrate the process of "DeXification" of the Android app, I'll take the open source VNC client - https://github.com/CyberShadow/android-vnc-viewer and try to optimize it for DeX mode.

Why have I chosen the VNC client? It is the most convenient to work with the remote machine on a large screen with a mouse and a keyboard. So, DeX mode of this kind of applications seems the most comfortable way.

  1. The first thing you need to support the DeX mode is to enable resize of the application window. For this I simply add to the 'Application' section of the manifest:

    android: resizeableActivity = "true"
  2. The next step is to ensure that the application correctly responds to window resize. Add to the manifest in the 'activity' section:

    android: configChanges = "orientation | keyboardHidden | screenSize | smallestScreenSize | density | screenLayout"

    Add a meta-tag to the 'application' section to prevent application restarting on entering / exiting DeX:

    <meta-data android: name = "com.samsung.android.keepalive.density" android: value = "true" />
  3. This VNC client supports the hardware mouse, so I did not have to handle MotionEvents in the Activity. It was enough just to specify the type of the default manipulator - Hardware Mouse:

    inputHandler = getInputHandlerById(R.id.itemInputHardwareMouse);

    And now the application supports clicking on the right and left mouse buttons.

    You can refer to https://developer.android.com/reference/android/view/MotionEvent.html and https://developer.samsung.com/samsung-dex/modify-optimizing.html for more information about handling mouse events.

  4. VNC client is the most convenient in full-screen mode. To do this, open the application in immersive mode and hide the system navigation bar:

    InonConfigurationChanged method we add:

    View mDecor = getWindow().GetDecorView();
  5. Drag and drop:

    • Define DragListener:

      class DragEventListener implements View.OnDragListener {
       	public boolean onDrag (View view, DragEvent dragEvent) {
       		switch (dragEvent.getAction()) {
       		case DragEvent.ACTION_DROP:
       			doDrop (dragEvent.getClipData());
       		return true;
    • In onCreate method set listener for the view. In this case, it is canvas:

      VncCanvas.setOnDragListener (new DragEventListener ());
    • Implement the processing of the event:

      private void doDrop (ClipData clipData) {
      	if (clipData! = Null) {
       		int itemCount = clipData.getItemCount ();
       		for (int i = 0; i <itemCount; i ++) {
       			clipData.Item item = clipData.getItemAt (i);
       			if (item.getText ()! = Null) {
       				enterTextDialog.sendText (item.getText ().toString (), this);

So, you can use Drag and Drop to send text to the remote machine. Similarly it works with binary data (for example, files).

As a result, I have the android application, adapted to the DeX mode. Of course, some details could be improved, but I tried to show how with minimum effort create new mode of the existing app. During my work, I did not have to use additional SDKs. All the necessary functionality is available in the Android API since version 24.

The amount of work does not require a revision of the application architecture and does not exceed several dozen lines of code. I hope my experience will help you to optimize your application for Samsung DeX. The source code of the application available here : https://github.com/DeXEvangelistRussia/dex-vnc-viewer