Example 1: In the following command sequence, the adb devices command starts the adb server, but the list of devices does not appear. Stop the adb server and enter the following commands in the order shown. For the avd name, provide a valid avd name from your system. To get a list of avd names, type emulator -list-avds. Example 2: In the following command sequence, adb devices displays the list of devices because the adb server was started first. To see the emulator in the adb devices output, stop the adb server, and then start it again after using the emulator command and before using the adb devices command, as follows:.
For more information about emulator command-line options, see Using Command Line Parameters. If multiple devices are running, you must specify the target device when you issue the adb command. To specify the target, use the devices command to get the serial number of the target. Once you have the serial number, use the -s option with the adb commands to specify the serial number. In the following example, the list of attached devices is obtained, and then the serial number of one of the devices is used to install the helloWorld.
Note: If you issue a command without specifying a target device when multiple devices are available, adb generates an error. If you have multiple devices available, but only one is an emulator, use the -e option to send commands to the emulator. Likewise, if there are multiple devices but only one hardware device attached, use the -d option to send commands to the hardware device.
You can use adb to install an APK on an emulator or connected device with the install command:. You must use the -t option with the install command when you install a test APK. For more information, see -t. Instead, Android Studio handles the packaging and installation of the app for you.
You can use the forward command to set up arbitrary port forwarding, which forwards requests on a specific host port to a different port on a device. The following example sets up forwarding of host port to device port Use the pull and push commands to copy files to and from an device. Unlike the install command, which only copies an APK file to a specific location, the pull and push commands let you copy arbitrary directories and files to any location in a device.
In some cases, you might need to terminate the adb server process and then restart it to resolve the problem e. To stop the adb server, use the adb kill-server command. You can then restart the server by issuing any other adb command. You can issue adb commands from a command line on your development machine or from a script. The usage is:. If there's only one emulator running or only one device connected, the adb command is sent to that device by default. You can use the shell command to issue device commands through adb, or to start an interactive shell.
To issue a single command use the shell command like this:. To start an interactive shell on a device use the shell command like this:. Note: With Android Platform-Tools 23 and higher, adb handles arguments the same way that the ssh 1 command does. But, this change means that the interpretation of any command that contains shell metacharacters has also changed.
For example, the adb shell setprop foo 'a b' command is now an error because the single quotes ' are swallowed by the local shell, and the device sees adb shell setprop foo a b.
To make the command work, quote twice, once for the local shell and once for the remote shell, the same as you do with ssh 1. For example, adb shell setprop foo "'a b'".
Android provides most of the usual Unix command-line tools. For a list of available tools, use the following command:. Help is available for most of the commands via the --help argument.
Many of the shell commands are provided by toybox. General help applicable to all toybox commands is available via toybox --help. See also Logcat Command-Line Tool which is useful for monitoring the system log.
Within an adb shell, you can issue commands with the activity manager am tool to perform various system actions, such as start an activity, force-stop a process, broadcast an intent, modify the device screen properties, and more. While in a shell, the syntax is:. You can also issue an activity manager command directly from adb without entering a remote shell. See the Specification for intent arguments.
Options are: -D : Enable debugging. Prior to each repeat, the top activity will be finished. This command kills only processes that are safe to kill and that will not impact the user experience. Use with [-e perf true] to generate raw output for performance measurements. Required for test runners. Options are: -w : Wait for debugger when app starts. This command is helpful for testing your app across different screen sizes by mimicking a small screen resolution using a device with a large screen, and vice versa.
Example: am display-size x display-density dpi Override device display density. This command is helpful for testing your app across different screen densities on high-density screen environment using a low density screen, and vice versa. Example: am display-density to-uri intent Print the given intent specification as a URI. Specification for intent arguments For activity manager commands that take an intent argument, you can specify the intent with the following options:.
Within an adb shell, you can issue commands with the package manager pm tool to perform actions and queries on app packages installed on the device. You can also issue a package manager command directly from adb without entering a remote shell. Options: -f : See their associated file. Options: -g : Organize by group. Options: -f : List the APK file for the test package. Options: -r : Reinstall an existing app, keeping its data. This feature is only supported on certain devices.
This option forces adb to use the feature or fail if it is not supported with verbose information on why it failed. Options: -k : Keep the data and cache directories around after package removal.
On devices running Android 6. On devices running Android 5. Location values: 0 : Auto: Let system decide the best location. Note: This is only intended for debugging; using this can cause apps to break and other undesireable behavior. To help you develop and test your device management or other enterprise apps, you can issue commands to the device policy manager dpm tool.
Use the tool to control the active admin app or change a policy's status data on the device. List of all the devices connected to your computer will appear and your Android device will be one of them. But, i f you did not find your device in the above list then you will need to install the appropriate driver for your device.
If you already found your device on the above list then skip this step and proceed to the next one. So head to their website and find the drivers for your device. You can also search the XDA Developers for driver downloads without the extra software. Once you have downloaded the driver, you need to install them using the following guide:. From Device Manager click on Portable devices. You will find your Android phone under Portable Devices. Right-click on it and then click on Properties.
Switch to the Driver tab under your Phone Properties window. Under the Driver tab, click on Update driver. A dialogue box will appear. Click on Browse my computer for driver software. Browse to look for driver software on your computer and click Next. List of available drivers will appear and click on Install to install them.
After completing the above process, follow Method 3 again and now you will find your device in the list of devices attached. Once you have added it, you can simply type adb from the Command Prompt window whenever you want to use it and no matter which folder you are in. Click on the Environment Variables button.
Select it and click on Edit button. A new dialogue box will appear. Click on the New button. The choice is yours. However, before using them, you will have to learn how to use ADB or Fastboot. For that, you can find various guides on YouTube or Google related to the purpose you want.
I will provide general instructions about both tools here. If your device supports it, you can use Fastboot by simply rebooting to Fastboot mode.
In the Fastboot mode, type fastboot devices to verify that your device is detected. After that, you can use any of the following commands:. These are some of the popular adb commands. ADB and Fastboot are invaluable tools to tweak any Android device without much hassle. There are limitless things you can do using them. This is how you can download, install, and use them on your Windows computers.
You can also use these on Mac or Linux based systems. However, that will be a topic for another post. You can use the comment box to let us know if you need it or not. Support any Android device. Able to install custom ROMs. Able to Flash custom Recovery. You can also install Root. You can unlock or re-lock the device bootloader. Able to remove bloatware from your Android device.
0コメント