Android ADB Commands Using Batch File

This tip will show how to use a batch file for adb commands.

Preface

This tip is for Windows users, but the concept is the same for all platforms.

It will show how to set several adb commands into one batch file.

Introduction

When developing for Android platform, sometimes you find yourself typing the same commands in the adb(Android Debug Bridge), commands like granting permissions for internal files.

I find it much easier to create a batch file for each purpose and run it when necessary.

If you are not familiar with adb usage, read my article about it:

  • http://www.codeproject.com/Articles/825304/Accessing-internal-data-on-Android-device

What is a Batch File?

Batch files are script files that contain a series of commands that will be executed at the command interpreter (CMD on Windows). Linux also has the same feature, in fact much more flexible, called shell scripting.

More on Batch files can be found by clicking on the link below:

  • http://en.wikipedia.org/wiki/Batch_file

Common Usage

One of the common operations that I run constantly on my Android applications is to pull out my sqlite database to my PC in order to examine its structure. So, instead of typing the commands one by one, I created a batch file and named it db_lookup.bat.

This is the content of my batch file, simply type it in Notepad and change its extension from txt to bat as you save, in order to run it as batch file.

cd %ANDROID_SDK%/platform-tools

cd %ANDROID_SDK%/platform-tools

adb shell su -c "chmod 777 /data"
adb shell su -c "chmod 777 /data/data"
adb shell su -c "chmod 777 /data/data/your.packagename"
adb shell su -c "chmod 777 /data/data/your.packagename/databases"
adb shell su -c "chmod 777 /data/data/your.packagename/databases/MyDB"
adb pull /data/data/your.packagename/databases/MyDB C:\Users\Pavel\Desktop

cd %ANDROID_SDK%/platform-tools 

This command opens the directory of the adb accordingly to my system environment variable that specifies the location of my SDK directory on my machine.

You can simply replace the %ANDROID_SDK% with a full path:

Assuming that your SDK directory are located at C:/Android/SDK:

cd C:/Android/SDK/platform-tools  

I use system variable because I can run the same batch file on other machines as well, no matter where the SDK folder is located (assuming that I set the %ANDROID_SDK% system variable ).

Other commands are simply grand file permissions in order to access it; the last line pulls the db file to my desktop.

Summary

Writing your adb commands in a batch file can save you a lot of time, especially when you are testing the same application on different devices.

Simply run your composed script and you are done.

转自:http://www.codeproject.com/Tips/827908/Android-ADB-Commands-Using-Batch-File

你可能感兴趣的:(android,shell,adb)