How to Unlock and Control Your Android Device Wirelessly from a Mac

4 min read

I was in the beautiful Dominican Republic on a workcation. It was a hot, sunny day, and I was excited to try some delicious local cuisine. I sat down at a restaurant, eager to enjoy a big fried fish with fried plantains. As I took my seat, my phone slipped out of my pocket and crashed to the ground. The screen shattered, rendering it unusable. Faced with a non-functional screen, I needed a solution to access my data and transfer it to my new phone. This led me on a journey to regain control of my device wirelessly. Here’s how I did it.

Requirements

Before you start, ensure you have the following:

  • A macOS computer.
  • An Android device with USB debugging enabled.
  • A USB cable for initial setup.
  • Scrcpy installed on your macOS computer.
  • ADB (Android Debug Bridge) installed on your macOS computer.

    Warning: Ensure that USB debugging was enabled on your device before the screen was cracked. Without USB debugging enabled, these steps will not work. If you’ve never had a use for developer options or USB debugging before, now you do. Make sure to enable these settings to prepare for situations like this in the future.

    Step 1: Install Scrcpy and ADB

    If you haven’t already installed Scrcpy and ADB, follow these steps:

    Install Homebrew (if you don’t have it already)

      Open Terminal and run the following command:

      ShellScript
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

      Install Scrcpy and ADB:

      In Terminal, run the following commands:

      ShellScript
      brew install scrcpy
      brew install android-platform-tools

      Step 2: Enable USB Debugging on Your Android Device

      1. Enable Developer Options:

      • Go to Settings > About phone.
      • Tap Build number seven times until you see a message saying you are now a developer.

      2. Enable USB Debugging:

      • Go to Settings > System > Developer options.
      • Toggle on USB debugging.

      Step 3: Connect Your Device via USB

      • Connect Your Android Device to Your Mac
      • Authorize the Connection:
        • If prompted, authorize the connection on your Android device by tapping “Allow”.

        Step 4: Create the Shell Script for Wireless Connection

        1. Open a Text Editor Open your preferred text editor on macOS (e.g., TextEdit).

        2. Create the Script:

          ShellScript
          #!/bin/bash
          
          # Ensure the device is connected via USB first
          echo "Please ensure your device is connected via USB and USB debugging is enabled."
          
          # Enable TCP/IP on port 5555
          echo "Enabling TCP/IP on port 5555..."
          adb tcpip 5555
          
          # Prompt the user to enter the device IP address
          read -p "Please enter the IP address of your device: " DEVICE_IP
          
          # Validate the IP address format
          if [[ ! $DEVICE_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
              echo "Invalid IP address format. Please enter a valid IP address."
              exit 1
          fi
          
          # Connect to the device wirelessly
          echo "Connecting to the device wirelessly at $DEVICE_IP:5555..."
          adb connect $DEVICE_IP:5555
          
          # Check if the connection was successful
          if adb devices | grep -q "$DEVICE_IP:5555"; then
              echo "Successfully connected to $DEVICE_IP:5555"
          else
              echo "Failed to connect to $DEVICE_IP:5555. Please check your device and try again."
              exit 1
          fi
          
          # Start scrcpy
          echo "Starting scrcpy..."
          scrcpy

          3. Save the file as something like scrcpy_wireless.sh in your preferred directory.

          4. Make the Script Executable:

          Open Terminal and navigate to the directory where you saved the script. For example, if you saved it in your home directory:

          ShellScript
          cd ~

          Make the script executable by running:

          ShellScript
          chmod +x scrcpy_wireless.sh

          Step 5: Find Your Device’s IP Address:

          Get the IP Address Using ADB

          Open Terminal and run the following command to get your device’s IP address:

          ShellScript
          adb shell ip route

          Look for the IP address in the output. It typically appears after the src keyword. It should look like 192.168.x.x.

          192.168.1.13 would be your IP address in this case.

          Alternatively, Get the IP Address on Your Device

          • On your Android device, go to Settings > Network & internet > Wi-Fi.
          • Tap on the Wi-Fi network you are connected to.
          • Note the IP address listed (it should look like 192.168.x.x).

          Step 6: Unlock Your Device

          Due to Android’s security features, if your device is locked with a PIN, pattern, or password, you will need to unlock it to access the device fully. These security measures are in place to protect your data from unauthorized access. When the screen is cracked, this can pose a challenge. However, you can use ADB commands to unlock the device programmatically.

          Create a new script and Copy and paste the following script into your text editor. Replace YOUR_PIN with your actual PIN.

          ShellScript
          #!/bin/bash
          
          # Wake up the device
          adb shell input keyevent 26
          
          # Wait for the screen to wake up
          sleep 1
          
          # Swipe up to unlock
          adb shell input swipe 720 1600 720 800
          
          # Wait for the swipe action to complete
          sleep 1
          
          # Enter the PIN
          adb shell input text YOUR_PIN
          adb shell input keyevent 66
          • Save the file as unlock_device.sh in your preferred directory.
          • Make the Unlock Script Executable: as shown before chmod +x unlock_device.sh
          • Run the Unlock Script: ./unlock_device.sh

          Step 7: Run the Script

          In Terminal, run the script by entering:

          ShellScript
          ./scrcpy_wireless.sh

          When prompted, enter the IP address of your Android device.

          Step 8: Enjoy Wireless Control

          After running the script and entering your device’s IP address, scrcpy should start, allowing you to mirror and control your Android device wirelessly from your macOS computer.

          Conclusion

          My travels in the Dominican Republic were delightful until my phone fell out of my pocket and broke on the restaurant floor. Faced with a non-working screen, I sought a way to retrieve my data and move it to a new device. Scrcpy provided a crucial wireless control method. The following guide outlines the actions I performed to reclaim access and secure my vital information. Now, you too can benefit from this level of convenience and adaptability, even amidst unforeseen setbacks. Wishing you effortless wireless control of your device and safe journeys!