Skip to content

Display and control your Android device

Use ANDROID_SERIAL in OTG mode

dev224192bb8f65c0eea
diff --git a/app/src/usb/scrcpy_otg.c b/app/src/usb/scrcpy_otg.c
index c4987c24..45ceee1b 100644
--- a/app/src/usb/scrcpy_otg.c
+++ b/app/src/usb/scrcpy_otg.c
@@ -77,6 +77,13 @@ scrcpy_otg(struct scrcpy_options *options) {
struct scrcpy_otg *s = &scrcpy_otg;
const char *serial = options->serial;
+ if (!serial) {
+ // No explicit selection, check $ANDROID_SERIAL
+ serial = getenv("ANDROID_SERIAL");
+ if (serial) {
+ LOGI("Using ANDROID_SERIAL: %s", serial);
+ }
+ }
sc_sdl_set_hints(options->render_driver, options->disable_screensaver);
diff --git a/doc/otg.md b/doc/otg.md
index 7d31c0a7..f590509d 100644
--- a/doc/otg.md
+++ b/doc/otg.md
@@ -27,6 +27,9 @@ scrcpy --otg
scrcpy --otg -s 0123456789abcdef
```
+The serial may also be provided via the environment variable `ANDROID_SERIAL`
+(see [connection](connection.md#selection)).
+
It is possible to disable keyboard or mouse:
```bash