1

When I plug my phone into the DeX dock, my app window is minimized in the DeX taskbar. This is default behaviour.

I am using a Galaxy S8 running DeX 2.5.

I want my app to display (full-screen or windowed) immediately when plugged into the DeX.


What I have tried so far (as per advice on the Samsung DeX website)...

1 - I have applied the manifest meta-data that keeps the app process alive:

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

2 - I have applied the configChanges property to intercept config changes:

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

This works as expected when the device is rotated, or when the screen is resized within the DeX interface i.e. Activity.onConfigurationChanged(Configuration) runs.

But this does not get triggered by plugging the phone into the DeX.

3 - My activity has been set to resize in the manifest:

android:resizeableActivity="true"
android:supportsPictureInPicture="true"

  • Is there a way to get the window to automatically display when plugged into the Dex?
  • Is there a way to get a callback when plugged into the DeX, and then launch my app from that calllback?
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • What should happen when other apps request the same thing? Example I got app A and B installed. Both listen to a callback to launch their app. Which one should DeX open? – Zun Feb 25 '19 at 09:36
  • That is an interesting question - are you trying to say that you know this is not a supported feature and that you know this to be technically impossible, even with root or special Samsung signing keys? @ZUNJAE – Richard Le Mesurier Feb 25 '19 at 09:39
  • 1
    I think that to save Dex switching time app state is minimized and only when the user clicks from taskbar app is relaunched. And the meta-data given for configChanges only works afterward. – singularity Feb 25 '19 at 09:43
  • This is how it appears to be by default, yes. However the Terms and Conditions say that "most apps will close" which to me leaves the possibility that "some apps" might not close. I'd like to know how to write one of these apps that does not close - if that is at all possible. I have reached out to some developer experts at Samsung about this as well and hope to get feedback. I'll update as and when I find out more. @singularity – Richard Le Mesurier Feb 25 '19 at 09:52
  • @ZUNJAE following up on your comment. Based on code sent to my by a contact at Samsung, I've answered below. As you can see, there is no way of prioritising this approach at all, nor of preventing multiple apps from doing the same thing (so who gets to be in front? I don't know). It is not the most satisfying solution (given your concerns) but is the solution offered by Samsung (at least for the S8). – Richard Le Mesurier Mar 12 '19 at 11:29

1 Answers1

2

This info is only valid for DeX v2.5. Updates to DeX v3 broke the below code.


When a device is docked into, or undocked from, the DeX, the following intents are broadcast by the system:

  • android.app.action.ENTER_KNOX_DESKTOP_MODE
  • android.app.action.EXIT_KNOX_DESKTOP_MODE

Any app can register a receiver in the manifest to be notified when the device is docked:

<receiver android:name=".DexReceiver">
    <intent-filter>
        <action android:name="android.app.action.ENTER_KNOX_DESKTOP_MODE"/>
    </intent-filter>
</receiver>

Inside the receiver the app can relaunch itself.

public void onReceive(Context context, Intent intent) {
    Intent relaunch = context.getPackageManager().getLaunchIntentForPackage(BuildConfig.APPLICATION_ID);
    relaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(relaunch);
}

This causes the app to launch in a normal window when docked.


To ensure full-screen launching, there are 2 changes to make in the manifest.

1) Add DeX meta-data inside the application block:

<!--DeX FULL SCREEN LAUNCH SIZE-->
<meta-data
    android:name="com.samsung.android.dex.launchwidth"
    android:value="0"/>
<meta-data
    android:name="com.samsung.android.dex.launchheight"
    android:value="0"/>

Here the 0 values tell DeX to use the maximum width/height possible.

2) Add a layout block to the activity that is being launched:

<!--USE BIG ENOUGH DIMENSIONS TO FORCE FULL-SCREEN ON LAUNCH-->
<layout
    android:defaultWidth="5000dp"
    android:defaultHeight="5000dp"
    android:gravity="center"/>

Here the 5000dp values must be bigger than the screen that you are plugging into the DeX.

Both launch size blocks are recommended by Samsung in different places - my experience was that the second option worked on the S8 (DeX v2.5).

Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • I tried the both option 1 and 2 but app does not relaunch on full screen when we connect it to dex. But it does when we open the application on dex directly. Is there any other workaround? – ThunderDragon Sep 04 '19 at 13:41
  • @ThunderDragon at some point recently Knox updated and broke the above solutions. For our purposes we ended up enabling the Experimental Features on DeX so that is automatically restarted the app when plugged in. I don't think we managed to get it to launch full-screen though. We've settled for default DeX behaviour because getting info out of Samsung is impossible even with a direct contact at the company. Sorry can't be of more help. – Richard Le Mesurier Sep 04 '19 at 14:56
  • @RichardLeMesurier I checked with your code. One scenario it is failing, i.e if I launch the App in the phone before plugging into the DeX and after the app launch in the phone, I plug the phone into the DeX. In this case my app window is in minimized state instead of maximized. But if I don't launch the App in the phone and then plug in, it show app window in maximized mode. Any clue why it's happening like this? – Rahul Sep 05 '19 at 07:25
  • @Rahul like I said in the previous comment, we updated to DeX v3, enabled the experimental features and just went with those. – Richard Le Mesurier Sep 06 '19 at 06:00