Overview
TheScrcpy class is the main Android service that manages the client-side screen mirroring functionality. It handles socket connections to the scrcpy server, manages video and audio decoders, and processes touch and key events.
Package: org.client.scrcpy
Extends: android.app.Service
Starting the Service
start()
Initializes and starts the scrcpy service with screen mirroring.Surface
required
The Android Surface to render video output
String
required
Server address in format “host:port” (e.g., “127.0.0.1:7008”)
int
required
Height of the display surface in pixels
int
required
Width of the display surface in pixels
int
required
Network delay tolerance in milliseconds for frame dropping
Touch Event Handling
touchevent()
Processes touch events and sends them to the remote device with coordinate transformation.MotionEvent
required
The Android MotionEvent to process
boolean
required
Whether the remote device is in landscape orientation
int
required
Current display width in pixels
int
required
Current display height in pixels
boolean
Returns
true if the event was processed successfullyACTION_DOWN- First finger touchACTION_UP- Last finger liftACTION_MOVE- Touch movement (all fingers)ACTION_POINTER_DOWN- Additional finger touchACTION_POINTER_UP- Additional finger lift
ACTION_MOVE events:
Key Event Handling
sendKeyevent()
Sends a key event to the remote device.int
required
Android KeyEvent keycode (e.g.,
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_HOME)Lifecycle Methods
pause()
Pauses video and audio decoding without disconnecting.resume()
Resumes video and audio decoding after pause.StopService()
Stops all decoders and terminates the service.ServiceCallbacks Interface
Implement this interface to receive service events.setServiceCallbacks()
Registers a callback listener.ServiceCallbacks
required
Implementation of the ServiceCallbacks interface
void
Called when the remote device rotation changes and a new surface is needed
void
Called when the connection is lost or an error occurs
Connection Information
get_remote_device_resolution()
Returns the remote device’s native resolution.int[]
Array of two integers [width, height] representing the device resolution
check_socket_connection()
Checks if the socket connection is established.boolean
Returns
true if connected, false otherwiseConstants
String
Default local IP address:
"127.0.0.1"int
Default forwarding port:
7008int
Default ADB port:
5555Event Data Format
Touch and key events are serialized as byte arrays before transmission: Touch Event Format (20 bytes):See Also
- Video Decoder - Video stream decoding
- Audio Decoder - Audio stream decoding
- Event Controller - Server-side event handling
