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 theSTART_REMOTE boolean extra in your intent:
Via ADB Command
Via Android Intent
Constant Definition
The constant is defined inMainActivity.java:61:
How Headless Mode Works
Behavior Changes
When headless mode is enabled:UI Hidden
The main scroll view containing connection settings is hidden (
MainActivity.java:213-218, 273-278):Auto-Connect
On first launch, the app automatically attempts to connect using saved preferences (The target device address is loaded from
MainActivity.java:209-212):SharedPreferences key CONTROL_REMOTE_ADDR.State Persistence
The headless mode state is preserved across configuration changes (MainActivity.java:228):
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:- Triggers
- Exceptions
- Connection failure during initial connect
- Unexpected disconnection during active session
- Network timeout or error
User Options
The dialog provides two options:- Retry: Attempts to reconnect using the same saved configuration
- 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:Scenario 2: Tasker Integration
Use Tasker or similar automation apps: Task Configuration:- Action: Send Intent
- Action:
android.intent.action.MAIN - Cat:
Default - Package:
com.example.scrcpy - Class:
com.example.scrcpy.MainActivity - Extra:
start_remote_headless:true - 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:Target Device Address
Target Device Address
Must be saved in Format:
SharedPreferences under key Constant.CONTROL_REMOTE_ADDR.Setting:<ip_address>:<port> (port defaults to 5555 if omitted)Video Settings
Video Settings
Resolution, bitrate, and delay settings are loaded from saved preferences:
PREFERENCE_SPINNER_RESOLUTION: Video resolution indexPREFERENCE_SPINNER_BITRATE: Bitrate indexPREFERENCE_SPINNER_DELAY: Delay tolerance index
PreUtils.put().Control Settings
Control Settings
Touch and navigation settings:
CONTROL_NO: Disable touch control (boolean)CONTROL_NAV: Show navigation bar (boolean)
Limitations
- 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:Exit Behavior
In headless mode, the app usesfinishAndRemoveTask() instead of returning to the main UI:
