【安卓学习之myt】adb常用命令

█ 常用命令

  • 查看可连接操作的设备

adb devices

adb -s cf27456f devices

  • 查看安装的应用程序包

adb shell pm list packages 所有软件包

adb shell pm list packages -s 只输出系统的包

adb shell pm list packages -3 只输出第三方的包

  • 卸载应用程序包

adb uninstall com.gysl.interphone

adb uninstall com.youdo.smartbc

  • 安装应用程序包

adb install D:\123.apk 安装应用

adb -r install D:\123.apk 重新安装apk

  • 查看版本号

adb shell dumpsys package com.gysl.interphone | findstr versionName

adb shell "dumpsys package com.gysl.interphone | grep versionName"

adb shell "dumpsys package com.gysl.interphone | grep -E 'versionName|versionCode'"

  • 结束应用

adb shell am force-stop com.gysl.interphone

  • 清空应用缓存

adb shell pm clear com.xxx.xxx

  • 查看系统内存

adb shell cat /proc/meminfo

  • 文件管理

adb shell ls -l /sdcard/Temp/log 查看文件列表

adb pull /sdcard/Temp/log D:\Temp\ 将文件夹拷贝到电脑上

adb shell rm -r /sdcard/Temp/log 删除文件夹

  • 捕获设备上的输入事件,如按键事件

adb shell getevent

  • 打开设置页面

adb shell am start -n com.android.settings/.Settings 指定组件名

adb shell am start -a android.settings.SETTINGS 隐式调用

█ 其他命令

  • 抓取日志

adb shell logcat>D:\log.txt

adb shell "logcat | grep com.gysl.interphone" >D:\1.txt

adb shell logcat com.ifeng.news2 -v time >D:\log.txt 通过包名过滤日志

adb logcat -c 清除日志

adb logcat -b crash >error.txt 直接闪退(app无任何提示,搜索fatal exception 或者crash)

adb bugreport > log.txt 程序意外终止(app弹窗提示,搜索fatal exception 或者crash)

adb pull data/anr/traces.txt > anr_log.txt ANR无反应(app弹窗提示,搜索fatal exception 或者crash)

  • wifi连接设备

adb shell am start -n com.android.settings/.Settings 指定组件名

adb shell am start -a android.settings.SETTINGS 隐式调用

  • 输入文本(不支持中文,小屏幕用来输入wifi密码很方便)

adb shell input text nihao 确保输入框已经聚焦

  • 发送一个广播

adb shell am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS 锁屏的广播

adb shell am broadcast -a com.dfl.a9.camdown,

adb shell am broadcast -a com.dfl.a9.camup

  • 修改屏幕分辨率

adb shell wm size reset

adb shell wm size 480x640

adb shell wm size 960x1280

adb shell wm size 600x1280

adb shell wm size 1080x1920

  • 修改系统设置 状态栏

adb shell settings put global policy_control immersive.full=* 同时隐藏,实现全屏效果

adb shell settings put global policy_control immersive.status=* 隐藏状态栏

adb shell settings put global policy_control immersive.navigation=* 隐藏导航栏(所有界面)

adb shell settings put global policy_control immersive.navigation=apps 隐藏导航栏(所有应用)

adb shell settings put global policy_control immersive.navigation=com.a.b 隐藏导航栏(指定应用)

adb shell settings put global policy_control immersive.navigation=-com.a.b 隐藏导航栏(排除指定应用)

adb shell settings put global policy_control immersive.navigation=apps,-com.google.android.apps.nexuslauncher,-com.android.settings,-android,-com.google.android.GoogleCamera 隐藏虚拟键(但是不在桌面页、设置页、相机隐藏)

adb shell settings put global policy_control null 恢复系统默认

adb shell settings get global policy_control

  • 定制的查看led状态

adb shell cat /sys/class/leds/led-g/brightness

█ 案例

案例1 626设备上安装app和设置wifi

c 复制代码
C:\Users\Administrator>adb devices
List of devices attached
12344321        device
C:\Users\Administrator>adb shell am start -a android.settings.SETTINGS -------------- 打开设置页面设置wifi
Starting: Intent { act=android.settings.SETTINGS }
C:\Users\Administrator>adb shell pm list packages -3
package:com.youdo.hardware
package:com.youdo.smartbc
package:com.youdo.smart.hikbc
C:\Users\Administrator>adb uninstall com.youdo.smartbc
Success
C:\Users\Administrator>adb install D:\123.apk
Performing Push Install
D:\123.apk: 1 file pushed, 0 skipped. 4.2 MB/s (37406508 bytes in 8.596s)
        pkg: /data/local/tmp/123.apk
Success
C:\Users\Administrator>adb shell dumpsys package com.gysl.interphone | findstr versionName--------------查看版本号
    versionName=V1.0
C:\Users\Administrator>adb shell "dumpsys package com.gysl.interphone | grep -E 'versionName|versionCode'"
     versionCode=300 minSdk=22 targetSdk=27
     versionName=V1.0

案例2 获取设备的事件信息

c 复制代码
C:\Users\Administrator>adb shell getevent
add device 1: /dev/input/event3
  name:     "mtk-tpd"
add device 2: /dev/input/event0
  name:     "ACCDET"
add device 3: /dev/input/event1
  name:     "mtk-kpd"
add device 4: /dev/input/event2
  name:     "gpio_keys"
/dev/input/event1: 0001 0074 00000001
/dev/input/event1: 0000 0000 00000000
/dev/input/event1: 0001 0074 00000000
/dev/input/event1: 0000 0000 00000000

案例3 内存相关

c 复制代码
Microsoft Windows [版本 10.0.19045.6093]
(c) Microsoft Corporation。保留所有权利。

C:\Users\Administrator>adb shell cat /proc/meminfo
MemTotal:         924548 kB
MemFree:           12328 kB
MemAvailable:     425584 kB
Buffers:             944 kB
Cached:           423524 kB
SwapCached:        12792 kB
Active:           373820 kB
Inactive:         305668 kB
Active(anon):     127892 kB
Inactive(anon):   134288 kB
Active(file):     245928 kB
Inactive(file):   171380 kB
Unevictable:        2404 kB
Mlocked:            2404 kB
HighTotal:        427068 kB
HighFree:           1020 kB
LowTotal:         497480 kB
LowFree:           11308 kB
SwapTotal:        693404 kB
SwapFree:         524584 kB
Dirty:                72 kB
Writeback:             0 kB
AnonPages:        256032 kB
Mapped:           259372 kB
Shmem:              5252 kB
Slab:              73524 kB
SReclaimable:      18420 kB
SUnreclaim:        55104 kB
KernelStack:       12408 kB
PageTables:        26460 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     1155676 kB
Committed_AS:   19281688 kB
VmallocTotal:     499712 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
c 复制代码
C:\Users\Administrator>adb shell top
User 0%, System 1%, IOW 2%, IRQ 0%
User 154 + Nice 1 + Sys 405 + Idle 25709 + IOW 594 + IRQ 0 + SIRQ 0 = 26863

  PID PR CPU% S  #THR     VSS     RSS PCY UID      Name
11875  1   0% S    55 1085976K 101084K  fg u0_a20   com.gysl.interphone-----主进程
10216  1   0% S     1   1384K    696K  fg shell    logcat
  751  1   0% S    98 1070592K  87184K  fg system   system_server--系统关键进程,线程数98,可能内存碎片化
12083  2   0% S    29 1018484K  47356K  fg u0_a20   com.gysl.interphone:remote-----主进程的辅助服务
  281  0   0% S     2   3996K   1120K  fg wifi     /system/bin/ptt_socket_app
 3689  1   0% S    30 951468K  35948K  fg radio    com.android.phone
  291  2   0% S     6 921220K  45508K  fg root     zygote--系统关键进程
  300  2   0% S     1   1844K    896K  fg gps      /system/bin/loc_launcher
  308  0   0% S     3  10400K   3164K  fg system   /system/bin/audiod
 2565  3   0% S     1      0K      0K  fg root     kworker/3:2
 3325  0   0% S     1   1476K    808K  fg shell    /data/local/tmp/.studio/process-tracker
 3421  0   0% S    27 965944K  56628K  fg u0_a6    com.android.systemui--系统关键进程
 3441  0   0% S    16 934968K  25576K  bg u0_a4    android.process.media--后台进程
 3488  0   0% S    14 937036K  22748K  bg system   com.android.settings--后台进程
10088  0   0% S    24 986648K  63692K  fg u0_a10   com.google.android.tts

系统服务:system_server 线程数过高,可能导致内存碎片化。
后台进程:媒体、设置等应用后台驻留,占用显著内存。
语音合成服务缓存过多语音库,限制缓存大小,按需加载语音数据
c 复制代码
C:\Users\Administrator>adb shell settings get global policy_control
immersive.navigation=*

█ 相关资料

提示:这里是参考的相关文章

  1. 2022-10-09 ADB隐藏导航栏-俩娃的爸爸-CSDN博客
  2. 2024-07-11 关于【Adb】使用grep命令报错:"'grep' 不是内部或外部命令-小白成长记Ymr-CSDN博客
  3. 2024-03-15 adb shell input text 输入中文_adb input text-lsq126yx-CSDN博客

█ 免责声明

博主分享的所有文章内容,部分参考网上教程,引用大神高论,部分亲身实践,记下笔录,内容可能存在诸多不实之处,还望海涵,本内容仅供学习研究使用,切勿用于商业用途,若您是部分内容的作者,不喜欢此内容被分享出来,可联系博主说明相关情况通知删除,感谢您的理解与支持!

转载请注明出处:
https://blog.csdn.net/ljb568838953/article/details/156416305

相关推荐
阿巴斯甜17 小时前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker17 小时前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq952718 小时前
Andorid Google 登录接入文档
android
黄林晴19 小时前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack
冬奇Lab1 天前
Android触摸事件分发、手势识别与输入优化实战
android·源码阅读
城东米粉儿1 天前
Android MediaPlayer 笔记
android
Jony_1 天前
Android 启动优化方案
android
阿巴斯甜1 天前
Android studio 报错:Cause: error=86, Bad CPU type in executable
android
张小潇1 天前
AOSP15 Input专题InputReader源码分析
android
_小马快跑_2 天前
Kotlin | 协程调度器选择:何时用CoroutineScope配置,何时用launch指定?
android