24 Mayıs 2014 Cumartesi

Some Useful Commands for ADB in Windows

ADB, Android Debug Bridge, is a command-line utility included with Google�s Android SDK. ADB can control your device over USB from a computer, copy files back and forth, install and uninstall apps, run shell commands, and more.
Adb is a connection between your android and computer.

Besides the times when we've broken something and need to fix it, there are plenty of reasons why an advanced Android user would want to talk to his or her device. To do that, you need to have a few tools and know a few commands.
Now Here We talking about some basic commands for adb.First you setup adb in windows by this tutorial.

Install ADB (Android Debug Bridge) in Windows


For adb setup you must turn on USB Debugging in your Android Phone.
Read this for More;

Some Basic ADB Commands


View connected device(s)


Use this to view all connected devices and list their IDs.
adb devices
If multiple devices are attached, use adb -s DEVICE_ID to target a specific device.

Push a File in Android Device

If you want to move a file onto your Android device programmatically, you want to use the adb push command. You'll need to know a few parameters, namely the full path of the file you're pushing, and the full path to where you want to put it. Let's practice by placing a short video (in my case that is Flash Trailor Video) into the Movies folder on your device storage.


I copied the flash.mp4 file into the adb folder so I didn't need to type out a long path to my desktop. I suggest you do the same. I jumped back to the command line and typed "adb push flash.mp4 /sdcard/Movies/" and the file copied itself to my Xolo A500S, right in the Movies folder. If I hadn't dropped the file into my adb folder, I would have had to specify the full path to it -- something like C:\Users\Prophet\Desktop\flash.mp4. Either way works, but it's always easier to just drop the file into your tools folder and save the typing.
You also have to specify the full path on your device where you want the file to go.Windows users need to remember that on Android, you use forward slashes (one of these -- / ) to switch folders because it's Linux.

Pull a File From Android Device

If adb push sends files to your Android device, it stands to reason the adb pull command gets them out. That's exactly what it does, and it works the same way as the adb push command did. You need to know both the path of the file you want to pull off, as well as the path you want it placed into. You can leave the destination path blank and it will drop the file into your tools folder to make things easy. 

In this example, I did it the hard way so you can see what it looks like. The path of the file on the device is "/sdcard/Movies/flash.mp4" and I put it on my Windows 8 desktop at "C:\Users\Prophet\Desktop". Again, the easy way it to just let it drop into your adb folder by not giving a destination, which would have been "adb pull /sdcard/Movies/superfreak.mp4". Remember your forwards slash for the Android side, and you'll have no problems here.

ADB Reboot Command

Yeah Buddy you are right this command can make your phone reboot(restart). You just type adb reboot your phone gonna  going to reboot.
adb reboot

ADB Reboot Bootloader 

This command can make your phone reboot and start it from bootloader.Not only can you reboot your device, you can specify that it reboots to the bootloader. This is awfully handy, as sometimes those button combos are touchy, and if you have a lot of devices you can never remember them all.
Most devices can also boot to the recovery directly with the "adb reboot recovery" (note there is no hyphen in this one) and some can't. It won't hurt anything to try, and if yours can't nothing will happen.
adb reboot-bootloader

ADB Shell Commands


The adb shell is like you run your Android Terminal via remote.With this command you can view and manage your android device file or folder structure. The adb shell command confuses a lot of folks. There are two ways to use it, one where you send a command to the device to run in its own command line shell, and one where you actually enter the device's command shell from your terminal. In the image above, I'm inside the device shell, listing the flies and folders on the device. Getting there is easy enough, just type "adb shell" and enter. Once inside, you can escalate yourself to root if you need to. I'll warn you, unless you're familiar with an ash or bash shell, you need to be careful here -- especially if you're root. Things can turn south quickly if you're not careful. If you're not familiar, ash and bash are command shells that a lot of folks use on their Linux or Mac computers. It's nothing like DOS. 
adb shell
The other method of using the adb shell command is in conjunction with one of those Ash commands your Android device can run. You'll often use it for more advanced tasks like changing permissions of files or folders, or running a script. Using it is easy -- "adb shell ". An example would be changing permissions on a file like so: "adb shell chmod 666 /data/somefile". As mentioned, be very careful running direct commands using these methods.

Install and Uninstall an application

Install a Application

While adb push can copy files to our Android devices, adb install can actually install .apk files. Using it is similar to use the push command, because we need to provide the path to the file we're installing. That means it's always easier to just drop the app you're installing into your tools folder. Once you've got that path, you tell your device to sideload it like this: "adb install TheAppName.apk".

If you're updating an app, you use the -r switch: "adb install -r TheAppName.apk". There is also a -s switch which tries to install on the SD card if your ROM supports it, and the -l switch will forward lock the app (install it to /data/app-private). there are also some very advanced encryption switches, but those are best left for another article.

And finally, you can uninstall apps by their package name with "adb uninstall TheAppName.apk". Uninstall has a switch, too. The -k switch will uninstall the app but leave all the app data and cache in place.

# example
adb install -r ~/application.apk

Uninstall an application


adb uninstall PACKAGE_NAME

# example
adb uninstall com.growingwiththeweb.example

ADB Logcat

The adb logcat command is one of the most useful commands for some folks, but just prints a bunch of gibberish unless you understand what you're seeing. It returns the events written to the various logs in the running Android system, providing invaluable information for app developers and system debuggers. Most of us will only run this one when asked by one of those developers, but it's very important that we know how to use it correctly.
adb logcat

To see the log output on your computer screen, just type "adb logcat" and hit enter. Things can scroll by pretty fast, and chances are you won't find what you're looking for. There are two ways to handle this one -- filters, or text output.

The filter switch is used when a developer has placed a tag in his or her application, and wants to see what the event logs are saying about it. If it's needed, the developer will tell you what tag to append to the command. The text output is more useful, as it logs to a .txt file on your computer for reading later. Evoke is like so: "adb logcat > filename.txt". Let it run while you're doing whatever it takes to crash the app or system program you're debugging, then close it with the CTRL+C keystroke. You'll find the full log file saved in the directory you're working from, likely your tools folder. This is what you'll send to the developer.

Be warned that sensitive information can be contained in the log files. Be sure you trust the person you're sending them to, or open the log file in a text editor and see just what you're sending and edit as necessary.

There are plenty of other switches for the logcat command.  Developers can choose between the main, event, or radio logs, save and rotate log files on the device or their computer, and even change the verbosity of the log entries. These methods are a bit more advanced, and anyone interested should read the Android developer documentation.

Related Articles

Hiç yorum yok:

Yorum Gönder