Skip to content

a simple script and how-to force enable desktop mode on android and stream it using scrcpy

Notifications You must be signed in to change notification settings

1999AZZAR/android-desktop-mode-scrcpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Virtual Display for Android Devices

Overview

This tool creates a virtual display on your Android device and streams it using scrcpy. It's perfect for extending your Android device's screen or testing multi-display applications without additional hardware. The tool is available as both a Bash script (.sh) for Linux/macOS and a Batch file (.bat) for Windows.

Prerequisites

  • Computer running Windows, Linux, or macOS
  • Android device with USB debugging enabled
  • USB cable to connect your device

Required Software

  1. Android Debug Bridge (ADB)
  2. Scrcpy

Don't worry if you don't have these yet - the setup guide below will walk you through installation!

Step-by-Step Setup Guide for Beginners

1. Setting Up Your Android Device

  1. Enable Developer Options:

    • Go to Settings > About phone
    • Tap Build number 7 times until you see "You are now a developer!"
  2. Enable USB Debugging:

    • Go back to Settings
    • Find Developer options (may be under System or Advanced)
    • Toggle on USB debugging
  3. Connect Your Device:

    • Connect your Android device to your computer using a USB cable
    • When prompted on your Android device, tap Allow to authorize USB debugging

2. Installing ADB (Android Debug Bridge)

Windows

  1. Download the Platform Tools:

  2. Install ADB:

    • Extract the ZIP file to a location you can easily find (e.g., C:\adb)
    • Add the ADB location to your PATH:
      • Right-click on Start > System
      • Click Advanced system settings
      • Click Environment Variables
      • Under System Variables, find and select Path, then click Edit
      • Click New and add the path to your ADB folder (e.g., C:\adb)
      • Click OK on all dialogs
  3. Verify Installation:

    • Open Command Prompt (search for "cmd" in Start menu)
    • Type adb version and press Enter
    • You should see version information if installed correctly

Linux/macOS

  1. Install ADB using package manager:

    For Ubuntu/Debian:

    sudo apt update
    sudo apt install adb

    For macOS (using Homebrew):

    brew install android-platform-tools
  2. Verify Installation:

    • Open Terminal
    • Type adb version and press Enter
    • You should see version information if installed correctly

3. Installing Scrcpy

Windows

  1. Download Scrcpy:

  2. Install Scrcpy:

    • Extract the ZIP file to a location you can easily find (e.g., C:\scrcpy)
    • Add the Scrcpy location to your PATH (follow the same steps as for ADB)
  3. Verify Installation:

    • Open Command Prompt
    • Type scrcpy --version and press Enter
    • You should see version information if installed correctly

Linux

  1. Install using package manager:

    For Ubuntu/Debian:

    sudo apt update
    sudo apt install scrcpy

    For other distributions, check Scrcpy's documentation

  2. Verify Installation:

    • Open Terminal
    • Type scrcpy --version and press Enter
    • You should see version information if installed correctly

macOS

  1. Install using Homebrew:

    brew install scrcpy
  2. Verify Installation:

    • Open Terminal
    • Type scrcpy --version and press Enter
    • You should see version information if installed correctly

4. Using the Virtual Display Script

Windows

  1. Download the Script:

    • Save the virtual_display.bat file to a location on your computer
  2. Run the Script:

    • Double-click the virtual_display.bat file
    • Alternatively, open Command Prompt, navigate to the script's location, and type virtual_display.bat

Linux/macOS

  1. Download the Script:

    • Save the virtual_display.sh file to a location on your computer
  2. Make the Script Executable:

    • Open Terminal and navigate to the script's location
    • Run chmod +x virtual_display.sh to make it executable
  3. Run the Script:

    • In Terminal, run ./virtual_display.sh

What to Expect (All Platforms)

  • The script will create a virtual 1920x1080 display on your Android device
  • Scrcpy will launch, showing this virtual display
  • You can interact with this display using your mouse and keyboard
  • When you're done, close the script window (or use Ctrl+C in Terminal) to remove the virtual display

Troubleshooting

Common Issues and Solutions

  1. "ADB is not installed or not in PATH":

    • Make sure you've added the ADB folder to your PATH
    • Try opening a new command window
    • Try using the full path to adb in the script
  2. "No Android device connected":

    • Check your USB cable
    • Make sure USB debugging is enabled
    • Try unplugging and reconnecting your device
    • On your Android device, check for a USB debugging authorization prompt
    • Run adb devices to verify connection
  3. "Failed to detect the new display ID":

    • Some devices may have limitations with virtual displays
    • Try modifying the script to increase the wait time (change sleep 2 or timeout /t 2 to a higher number)
  4. "Scrcpy is not installed or not in PATH":

    • Make sure you've added the Scrcpy folder to your PATH
    • Try opening a new command window
    • Try using the full path to scrcpy in the script
  5. Virtual display appears but is glitchy:

    • Try reducing the resolution in the script (change 1920x1080/240 to 1280x720/240)
    • Try reducing bitrate or FPS settings
  6. Permission errors on Linux/macOS:

    • Make sure the script is executable: chmod +x virtual_display.sh
    • If having issues with ADB, try running the script with sudo: sudo ./virtual_display.sh

Device-Specific Notes

  • Some Samsung devices require additional steps to enable Developer Options
  • On newer Android versions, you may need to enable "Wireless debugging" even for USB connections
  • Some devices may require specific USB drivers to work correctly with ADB
  • Not all Android devices support virtual displays; this feature is typically available on devices running Android 4.4 (KitKat) or higher

Customizing Your Virtual Display

You can modify the following parameters in the script:

  1. Resolution: Change 1920x1080/240 to your preferred resolution (e.g., 3840x2160/480 for 4K)

    • Format is WIDTHxHEIGHT/DPI
  2. Scrcpy settings:

    • Bitrate: Change -b 24M to your preferred bitrate (lower for slower connections)
    • FPS: Change --max-fps=60 to adjust frame rate
    • Window Title: Change --window-title="Pixel" to your preferred title

Advanced Features

  • You can create multiple virtual displays by running the script multiple times
  • The virtual display persists on your device until explicitly removed
  • The script automatically detects and uses the ID of the newly created display

Script Comparison: Linux vs Windows

Both scripts provide the same functionality but use platform-specific commands:

Feature Linux/macOS (.sh) Windows (.bat)
Command checking command -v where
Process delay sleep 2 timeout /t 2
Text search grep findstr
Signal handling trap cleanup EXIT Manual cleanup procedure
Script execution ./virtual_display.sh virtual_display.bat

Contributing

Feel free to suggest improvements or report issues by contacting the script author.

License

This project is available for free use and modification.

Disclaimer

This script modifies your Android device settings. While it's designed to clean up after itself, always ensure you have important data backed up before using tools that modify system settings.

About

a simple script and how-to force enable desktop mode on android and stream it using scrcpy

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published