文章目录
一、ADB 简介
adb工具即Android Debug Bridge(安卓调试桥) tools。它就是一个命令行窗口,用于通过电脑端与模拟器或者真实设备交互。
二、ADB 常用命令
我把日常工作常用的命令都列在了下面,大家掌握下面这些也足够应付工作上的基本需求了。其他命令请自行百度学习。
2.1、查看连接的设备
adb devices
2.2、进入设备终端
adb shell
2.3、将apk安装到设备上
*.apk代表:安装当前目录下所有的apk文件
adb install xxx.apk
2.4、执行shell命令
adb shell command
2.5、从电脑上发送文件到设备
adb push <本地路径> <远程路径>
![](/qrcode.jpg)
2.6、从设备上发送文件到电脑
adb pull <远程路径> <本地路径>
2.7、查看帮助信息
adb help
2.8、查看设备日志
adb logcat
2.9、重启设备
adb reboot
2.10、查看所有安装apk的包
pm list packages
2.11、根据某个关键字查找包
pm list packages | grep tencent
2.12、查看包安装位置
pm list packages -f
2.13、查看当前的Activity
adb shell "dumpsys window | grep mCurrentFocus
三丶ADB 高级命令
3.1、进入某个界面
adb shell "am start com.android.launcher3/com.android.launcher3.Launcher"
3.2、清理 log
adb shell logcat -c
3.3、将log保存到本地
adb logcat > D:xxx.txt
3.4、查看设备的所有功能
adb shell pm list features
3.5、获取系统属性
adb shell getprop xxx
3.6、设置系统属性
adb shell setprop xxx
3.7、开启TP画线
adb shell settings put system show_touches 1 && adb shell settings put system pointer_location 1
3.8、模拟按键
模拟返回(back)事件
adb shell input keyevent 4
键值表在:frameworks/base/core/java/android/view/KeyEvent.java
3.9、发送 broadcast
广播模型:
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ("com.jlink.service.invisible".equals(action)) {
//1
if(intent.hasExtra("invisible")){
boolean show = intent.getBooleanExtra("invisible", true); //2
NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();
if (show) {
if (mNavigationBarView != null) return;
createNavigationBar(result);
SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_NAVIGATION_BAR, true);
}else{
if (mNavigationBarView == null) return;
mNavigationBarController.removeNavigationBarView();
//mNavigationBarView = null;
SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_NAVIGATION_BAR, false);
}
}else{
Log.w("StatusBar","didn't contain navigation_bar_show key");
}
}
//add end
}
};
解析:
1处,com.jlink.service.invisible 表示广播的唯一 action
2处,invisible 表示广播通信中,intent携带过来的值。
ADB发送广播:
adb shell am broadcast -a com.jlink.service.invisible --ez invisible false
综上所述,这条命令就很好理解了。
com.jlink.service.invisible 表示 action
invisible false 表示设置 invisible 的值为false
3.10、获取root权限
adb shell root
3.11、重新挂载系统分区
前提:拥有root权限
adb shell remount;
四、其他
1、Android Studio 的ADB路径
SDK/platform-tools
2、常见问题
- 1、 remote couldn’t create file: Read-only file system**
报错意思:远程无法创建只读文件系统
分析原因:没有root 权限,所以无法对手机内存进行读取或修改
解决方式:adb root;adb remount;