Use ADB (Android Debug Bridge) to work with the emulator - Dual-screen (2024)

  • Article

ADB is an important tool for developers because it allows you to interact with Android emulators, and also with connected devices. There are many features covered in the ADB documentation but here are some useful commands:

  • adb kill-server and adb start-server – stop and start the ADB service if needed
  • adb devices – list the devices available (including emulators and phones or tablets attached to your computer)
  • adb install – install APK files
  • adb shell – execute commands on the Android system, for example:
    • adb shell pm list packages – list all the packages installed
    • adb shell pm path com.example.someapp – gets the file system path of the package specified
  • adb pull – extract files from the emulator or device

Simulate app spanning

Another use for ADB is simulating input commands, such as automating spanning of an app on Surface Duo. These screenshots illustrate the process of spanning by grabbing the handle at the bottom of the window, and dragging it towards the hinge until the span indicator covers both screens:

Use ADB (Android Debug Bridge) to work with the emulator - Dual-screen (1)

You can simulate this gesture with ADB, using the following command:

adb shell input touchscreen swipe 675 1780 1350 1500 3000

The first four values are the start and end coordinates of the drag gesture, and the final value is elapsed time (milliseconds). The time is important because if you drag too fast, the app is “flung” to the other screen rather than spanned. Three seconds works well.

You can also simulate app spanning and other gestures as part of UI Testing.

Debug with ADB commands

Follow these steps to debug using ADB commands:

  1. Find your emulator device ID

    Run C:\>adb devices.

    emulator-5554 device
  2. Find the package you want to debug.

    Run adb shell pm list packages.

    package:com.android.managedprovisioningpackage:com.android.smspushpackage:com.android.wallpaper.livepickerpackage:com.android.storagemanagerpackage:com.android.bookmarkproviderpackage:com.android.settingspackage:com.android.calculator2package:com.android.vpndialogspackage:com.android.emailpackage:com.android.music
  3. Set the app to debug at startup (note the -w)

    Run adb shell am set-debug-app -w com.microsoft.device.display.samples.masterdetail.

  4. Start the app in the emulator.

    You will get a popup that the app is waiting for a debug to attach. You will need to re-run the set debug each time (or use --persistent option).

  5. Connect Android Studio Debugger

    In Android Studio menu options, select Run > Attach debugger. The emulator and process should be listed.

  6. Point to source code and set breakpoints.

Use ADB (Android Debug Bridge) to work with the emulator - Dual-screen (2024)

FAQs

Use ADB (Android Debug Bridge) to work with the emulator - Dual-screen? ›

Enable adb debugging on your device

To make it visible, enable Developer options. You can now connect your device with USB. You can verify that your device is connected by executing adb devices from the android_sdk /platform-tools/ directory. If connected, you'll see the device name listed as a "device."

How do I connect my ADB to my emulator? ›

Enable adb debugging on your device

To make it visible, enable Developer options. You can now connect your device with USB. You can verify that your device is connected by executing adb devices from the android_sdk /platform-tools/ directory. If connected, you'll see the device name listed as a "device."

How to connect Android phone to PC using ADB? ›

Steps for connecting the Android with ADB over TCP

Connect your android device with a laptop/pc using a USB cable. Then in the android device turn on developer options from settings, and in developer options turn on USB Debugging (PTP/ MTP).

How do I run ADB commands on my PC? ›

Windows Command Prompt
  1. Open the Command Prompt on your Windows computer. ...
  2. Connect your VR device to your computer using a USB cable.
  3. In the Command Prompt window, navigate to the location where you have ADB installed. ...
  4. Type the desired ADB command and press Enter to execute it.

How to install Android Debug Bridge on Windows? ›

Installing ADB on Windows

Step 1: Download and install the latest Android Studio release. Step 2: Once installed, click the More Actions button, and select SDK Manager from the dropdown. Step 3: In the SDK manager, click SDK Tools and select the following for installation: Android SDK Command-Line tools.

How do I connect my Android Emulator? ›

Set up an Android device emulator image

In Android Studio, go to Settings > Languages & Frameworks > Android SDK. In the SDK Tools tab, select the latest version of Android Emulator, and click OK. This action installs the latest version if it isn't already installed.

What is Android Debug Bridge in Android? ›

Android Debug Bridge (ADB) lets you connect your development workstation directly to your Android device so you can install packages and evaluate your changes. To learn the details of ADB, review its README.

How do I enable adb TCP IP mode on my Android phone? ›

6/ Enable TCP/IP mode: Run the command adb tcpip to enable TCP/IP mode on your device. Replace with the port number you want to use for the ADB connection (e.g., 5555). For example, adb tcpip 5555 . 7/ Disconnect the USB cable: After enabling TCP/IP mode, disconnect the USB cable from your Android device.

How can I connect my Android phone to my PC directly? ›

Connect an Android to a PC With Bluetooth
  1. Make sure bluetooth is turned on for both your Android device and your computer. ...
  2. Tap this device to pair with it. ...
  3. Once connected, on your PC right-click the bluetooth icon on the right side of the taskbar, then select either Send a File or Receive a File.
Aug 27, 2022

What is the ADB tool for PC? ›

Get the latest version

Android SDK Platform-Tools (ADB) is the official Google tool that allows you to use ADB commands on Android devices. With these commands, you can make modifications to Android devices just by connecting them to your PC via cable or network, without needing to root.

How to access Android phone from PC using CMD? ›

Now, connect your Android device to the computer using USB cable. Inside folder hold Shift + Right click menu >> Select 'Open command window here' option. It will open the folder using command prompt. Note– you can also open the folder path directly from the Run command in command prompt.

How do I run ADB from command line? ›

Open a command window in the folder by holding Shift, right-clicking an empty spot in the folder, and selecting Open command prompt/PowerShell here. Then you can start using ADB. Connect your phone and enter . ADB devices to see if it's working.

How to connect Android to PC with USB debugging? ›

Enable USB debugging on your Android phone
  1. Open the Settings app.
  2. Select System.
  3. Scroll to the bottom and select About phone.
  4. Scroll to the bottom and tap Build number 7 times.
  5. Return to the previous screen to find Developer options near the bottom.
  6. Scroll down and enable USB debugging.

What format is Google Android Debug Bridge Backup? ›

Android backups (. ab) are backups made by Android Debug Bridge (ADB). They are the preferred way of backing up an unrooted stock android device.

How do I enable ADB on BlueStacks? ›

How to enable Android Debug Bridge on BlueStacks 5
  1. Within the Settings menu, click on the "Advanced" tab and enable the toggle beside "Android Debug Bridge", as shown below.
  2. Click on "Save changes".
  3. To further debug an issue, search for "Command Prompt" within the Start Menu and click on "Run as administrator".
Feb 7, 2024

How to add ADB to path? ›

Setting up ADB Path on Windows: Android Tips.
  1. Step 1: Download Android SDK Platform Tools. ...
  2. Step 2: Extract the ZIP File. ...
  3. Step 3: Copy the ADB Folder Path. ...
  4. Step 4: Add ADB Path to Environment Variables. ...
  5. Step 5: Edit the “Path” Variable. ...
  6. Step 6: Add ADB Path. ...
  7. Step 7: Verify ADB Installation.
Sep 25, 2023

Top Articles
Latest Posts
Article information

Author: Clemencia Bogisich Ret

Last Updated:

Views: 5881

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Clemencia Bogisich Ret

Birthday: 2001-07-17

Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

Phone: +5934435460663

Job: Central Hospitality Director

Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.