Android ADB Commands Using Batch File

8 篇文章 2 订阅
2 篇文章 0 订阅
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 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值