Skip to content

Instantly share code, notes, and snippets.

@Tracnac
Last active September 23, 2022 16:54
Show Gist options
  • Select an option

  • Save Tracnac/8cd525368b2f1c898c9318e5430c1bef to your computer and use it in GitHub Desktop.

Select an option

Save Tracnac/8cd525368b2f1c898c9318e5430c1bef to your computer and use it in GitHub Desktop.
Setting for DEX #android

In the manifest :

android:resizeableActivity="true"

Detection DEX

Directement :

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) {
}

Ou via intent :

Manifest : receiver android:name=".MainActivity$DesktopModeReceiver" intent-filter action android:name="android.app.action.ENTER_KNOX_DESKTOP_MODE" action android:name="android.app.action.EXIT_KNOX_DESKTOP_MODE" intent-filter receiver

public class DesktopModeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if ("android.app.action.ENTER_KNOX_DESKTOP_MODE".equals(action)) {
        Toast.makeText(context, "Desktop mode ON", Toast.LENGTH_LONG).show();
        } 
        else if ("android.app.action.EXIT_KNOX_DESKTOP_MODE".equals(action))
        {
        Toast.makeText(context, "Desktop mode OFF", Toast.LENGTH_LONG).show();
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment