Skip to main content

What is Headless Mode?

Headless mode allows Scrcpy for Android to launch and automatically connect to a target device without displaying the main configuration UI. This is ideal for automation, kiosk applications, or scenarios where user interaction should be minimized.
Headless mode is triggered by passing the START_REMOTE intent extra when launching the MainActivity.

Enabling Headless Mode

To launch the app in headless mode, include the START_REMOTE boolean extra in your intent:

Via ADB Command

Via Android Intent

Constant Definition

The constant is defined in MainActivity.java:61:

How Headless Mode Works

Behavior Changes

When headless mode is enabled:
1

UI Hidden

The main scroll view containing connection settings is hidden (MainActivity.java:213-218, 273-278):
2

Auto-Connect

On first launch, the app automatically attempts to connect using saved preferences (MainActivity.java:209-212):
The target device address is loaded from SharedPreferences key CONTROL_REMOTE_ADDR.
3

No History Saving

Connection history is not saved in headless mode (MainActivity.java:509-512):

State Persistence

The headless mode state is preserved across configuration changes (MainActivity.java:228):
This ensures that if the activity is recreated (e.g., due to rotation), it remains in headless mode.

Use Cases for Automation

Headless mode enables various automation scenarios:

Kiosk Mode

Deploy devices that automatically mirror another device’s screen on boot, useful for digital signage or monitoring displays.

Remote Support

Build remote support applications where users tap a “Get Help” button and their screen is automatically shared with support staff.

Testing Automation

Automated testing frameworks can programmatically mirror device screens for visual verification or recording.

Monitoring Systems

Create dashboard applications that monitor multiple devices by automatically connecting in headless mode.

Auto-Reconnect Behavior

Headless mode includes automatic reconnection logic when connections fail:

Reconnect Dialog

When a connection fails or drops in headless mode, a dialog is automatically displayed (MainActivity.java:816-831):

Reconnect Conditions

The auto-reconnect dialog appears only when:
  • Connection failure during initial connect
  • Unexpected disconnection during active session
  • Network timeout or error

User Options

The dialog provides two options:
  1. Retry: Attempts to reconnect using the same saved configuration
  2. Cancel: Exits the application completely using finishAndRemoveTask()
In standard (non-headless) mode, connection failures simply return to the main UI. The auto-reconnect dialog is exclusive to headless mode.

Integration Scenarios

Scenario 1: Boot-Time Auto-Connect

Create a boot receiver to start headless mode automatically:
AndroidManifest.xml:

Scenario 2: Tasker Integration

Use Tasker or similar automation apps: Task Configuration:
  1. Action: Send Intent
  2. Action: android.intent.action.MAIN
  3. Cat: Default
  4. Package: com.example.scrcpy
  5. Class: com.example.scrcpy.MainActivity
  6. Extra: start_remote_headless:true
  7. Target: Activity

Scenario 3: Programmatic Configuration

Set the target device before launching headless mode:

Scenario 4: Tile Service Quick Connect

Create a Quick Settings tile for one-tap connection:

Configuration Requirements

For headless mode to work properly, the following must be pre-configured:
Must be saved in SharedPreferences under key Constant.CONTROL_REMOTE_ADDR.Setting:
Format: <ip_address>:<port> (port defaults to 5555 if omitted)
Resolution, bitrate, and delay settings are loaded from saved preferences:
  • PREFERENCE_SPINNER_RESOLUTION: Video resolution index
  • PREFERENCE_SPINNER_BITRATE: Bitrate index
  • PREFERENCE_SPINNER_DELAY: Delay tolerance index
These are set via the UI or programmatically using PreUtils.put().
Touch and navigation settings:
  • CONTROL_NO: Disable touch control (boolean)
  • CONTROL_NAV: Show navigation bar (boolean)

Limitations

Be aware of these limitations when using headless mode:
  • No UI Fallback: If connection fails and user cancels retry, app exits entirely
  • No Configuration Changes: Cannot change target device without exiting and modifying preferences
  • History Not Saved: Connection history is disabled to avoid polluting logs with automated connections
  • Single Connection: Only supports connecting to one saved device address

Debugging Headless Mode

To troubleshoot headless mode issues:
For testing, manually set preferences via ADB before launching:

Exit Behavior

In headless mode, the app uses finishAndRemoveTask() instead of returning to the main UI:
This ensures the app doesn’t leave background tasks running when disconnected.