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.The Android Surface to render video output
Server address in format “host:port” (e.g., “127.0.0.1:7008”)
Height of the display surface in pixels
Width of the display surface in pixels
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.The Android MotionEvent to process
Whether the remote device is in landscape orientation
Current display width in pixels
Current display height in pixels
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.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.Implementation of the ServiceCallbacks interface
Called when the remote device rotation changes and a new surface is needed
Called when the connection is lost or an error occurs
Connection Information
get_remote_device_resolution()
Returns the remote device’s native resolution.Array of two integers [width, height] representing the device resolution
check_socket_connection()
Checks if the socket connection is established.Returns
true if connected, false otherwiseConstants
Default local IP address:
"127.0.0.1"Default forwarding port:
7008Default 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
