Click here to Skip to main content
15,867,308 members
Articles / Mobile Apps / Android
Tip/Trick

Android ADB Commands Using Batch File

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
10 Oct 2014CPOL2 min read 60.6K   4   3
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:

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:

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 is 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.

History

  • 10th October, 2014: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionrun the same batch file on other machines - how? Pin
Member 133961326-Sep-17 2:17
Member 133961326-Sep-17 2:17 
QuestionADB Command line Pin
Member 344783230-Oct-15 5:43
Member 344783230-Oct-15 5:43 
AnswerRe: ADB Command line Pin
Pavel Durov31-Oct-15 21:37
professionalPavel Durov31-Oct-15 21:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.