注意: 应用包名默认为
com.example.app
adb shell am start -n "com.example.app/com.example.app.ui.basic.activity.LoginActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
注解:
com.example.app.ui.basic.activity.LoginActivity
为配有 action.MAIN
和 category.LAUNCHER
的Activity 即应用启动页面;adb shell dumpsys activity activities | grep 'ActivityRecord' | grep 'com.example.app'
结果:
Activities=[ActivityRecord{4df0741 u0 com.example.app/.ui.client.MainActivity t17}, ActivityRecord{45c40f u0 com.example.app/.ui.client.activity.InformationUnreadActivity t17}]
* Hist #1: ActivityRecord{45c40f u0 com.example.app/.ui.client.activity.InformationUnreadActivity t17}
* Hist #0: ActivityRecord{4df0741 u0 com.example.app/.ui.client.MainActivity t17}
Run #1: ActivityRecord{45c40f u0 com.example.app/.ui.client.activity.InformationUnreadActivity t17}
Run #0: ActivityRecord{4df0741 u0 com.example.app/.ui.client.MainActivity t17}
mResumedActivity: ActivityRecord{45c40f u0 com.example.app/.ui.client.activity.InformationUnreadActivity t17}
mLastPausedActivity: ActivityRecord{4df0741 u0 com.example.app/.ui.client.MainActivity t17}
ResumedActivity: ActivityRecord{45c40f u0 com.example.app/.ui.client.activity.InformationUnreadActivity t17}
分析关键字:
mResumedActivity
: 当前显示activity为InformationUnreadActivity
mLastPausedActivity
最近停止显示的Activity为 mLastPausedActivity
adb shell dumpsys window displays
输出(省略):
WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
Display: mDisplayId=0
init=1080x1920 420dpi cur=1080x1920 app=1080x1794 rng=1080x1017-1794x1731
deferred=false mLayoutNeeded=false mTouchExcludeRegion=SkRegion((0,0,1080,1920))
mLayoutSeq=500
....
注解:
cur=1080x1920
机器为1080 X 1920 分辨率的机器注解: 冷启动指App 从0到完全加载的过程,热启动指:app从后台进入前台,重新显示的过程
假设:com.example.app
为测试应用包名,注意启动的Activity必须在清单文件AndroidManifest.xml
中设置 Activity 属性exported=true
冷启动
模拟冷启动,强行停止应用com.example.app
adb shell am force-stop com.example.app
获取启动时间
adb shell am start -W com.example.app/.ui.client.MainActivity
输出结果
Status: ok
Activity: com.example.app/.ui.client.MainActivity
ThisTime: 7198 该activity启动耗时
TotalTime: 7198 应用自身启动耗时=ThisTime+应用application等资源启动时间
WaitTime: 7346 系统启动应用耗时=TotalTime+系统资源启动时间
Complete
热启动
模拟按Home键
adb shell input keyevent 3
同上
模糊查找包名
adb shell pm list packages | grep com.example
清除所有与该包名相关的数据,deletes all data associated with a package.
adb shell pm clear com.example.app
adb install [options] sample.apk
[-r] replace existing application
[-s] install application on sdcard
adb uninstall [options] sample.apk
[-k] means keep the data and cache directories
adb shell am force-stop [options] <app package name >
adb shell dumpsys meminfo [pid or 空]
adb shell dumpsys meminfo
显示手机每个应用内存使用情况
Applications Memory Usage (in Kilobytes):
Uptime: 69236415 Realtime: 69236415
Total PSS by process:
121,950K: com.example.app:pushcore (pid 29262)
88,714K: system (pid 1882)
68,646K: com.exinetian.app (pid 28829 / activities)
63,149K: com.google.android.googlequicksearchbox:search (pid 2527)
48,624K: com.google.android.gms.persistent (pid 2533)
45,421K: com.google.android.gms (pid 2691)
45,059K: com.google.android.apps.nexuslauncher (pid 2545 / activities)
44,975K: com.android.systemui (pid 2000)
29,179K: com.android.vending (pid 26823)
25,800K: com.google.android.inputmethod.latin (pid 1991)
16,701K: com.android.phone (pid 2126)
12,922K: audioserver (pid 1634)
10,259K: com.google.android.googlequicksearchbox:interactor (pid 2416)
adb shell dumpsys meminfo
#得到pid
adb shell ps -ef | grep com.example.app
# 查看进程28829 内存使用情况
adb shell dumpsys meminfo 28829
输出:
** MEMINFO in pid 28829 [com.exinetian.app] **
Pss Private Private SwapPss Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 17072 17004 0 0 27264 23545 3718
Dalvik Heap 5870 5800 0 0 7523 3762 3761
Dalvik Other 2653 2652 0 0
Stack 140 140 0 0
Ashmem 5 0 0 0
Other dev 24 0 24 0
.so mmap 5388 160 2148 0
.apk mmap 3434 1856 356 0
.ttf mmap 256 0 216 0
.dex mmap 18456 13340 1244 0
.oat mmap 228 0 80 0
.art mmap 7737 7052 240 0
Other mmap 5642 4 4360 0
Unknown 1433 1416 0 0
TOTAL 68338 49424 8668 0 34787 27307 7479
解析:
参见 http://developer.android.com/tools/help/adb.html#am
adb shell am start [options]
举例:adb shell am start -a android.intent.action.MAIN
举例:adb shell am start -n com.example.app.android.emop/.activity.login.LoginActivity
adb shell am startservice [options]
举例:
举例:adb shell am startservice -a com.lt.test.action.ONESERVICE
举例:adb shell am startservice -n com.example.app.android.emop/.MyService
adb shell am broadcast [options]
举例:
举例:adb shell am broadcast -a EMOP_OFF_LINE_ASSIGN_TASK //when the permission
<receiver android:permission="com.example.permission.EMOP_SERVICE_RECEIVER" >
<intent-filter>
<action android:name="EMOP_OFF_LINE_ASSIGN_TASK"/>
</intent-filter >
</receiver>
举例:adb shell am broadcast -a "action_finish"(发送一个广播去关闭一个activity)
举例:adb shell am broadcast -a android.intent.action.MASTER_CLEAR(恢复出厂设置的方法,会清除内存所有内容)
举例:adb shell am broadcast -n com.lt.test/.MyBroadcast
<INTENT> specifications include these flags:
[-a <ACTION>]
[-d <DATA_URI>]
[-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[-n <COMPONENT>]
[-f <FLAGS>]
[<URI>]
案例1:
am start -a android.intent.action.VIEW -d http://www.baidu.com
am start -a android.intent.action.CALL -d tel:12345
am start -a android.intent.action.VIEW -d file:///sdcard/video.3gp -t video/*
案例2:
目的传入
pid 整数,值为10
str 字符串,值为"hello, world"
am start -a android.intent.action.MAIN -n \
net.yurushao.demo/net.yurushao.demo.ExampleActivity --ei pid 10 --es str "hello, world"
adb logcat -s System.out ## 只查看System.out 的输出
-v
adb logcat -v time *** ## 能查看logcat缓存的日志,定位之前发生的异常信息
adb logcat -v brief
adb logcat -v process ##优先级 (进程ID) : 日志信息
adb logcat -v tag ##优先级 / 标签 : 日志信息
adb logcat -v thread ##优先级 ( 进程ID : 线程ID) 标签 : 日志内容
adb logcat -v raw ##只输出日志信息
adb logcat -v time ##日期 时间 优先级 / 标签 (进程ID) : 进程名称 : 日志信息
adb logcat -v long ##[日期 时间 进程ID : 线程ID 优先级 / 标签] 日志信息 **
adb logcat -b main/events/system
adb logcat -g
adb logcat *:E | grep "example" ## 搜索指定的错误信息
adb shell ps -t
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 268 180 c009b74c 0000875c S /init
cat /proc/34/status #进程状态
adb -s 20080411 shell cat /system/build.prop //设备信息
adb shell top // 查看设备cpu和内存占用情况
adb shell top -m 6 // 查看占用内存前6的app
adb shell top -n 1 // 刷新一次内存信息,然后返回
adb shell procrank // 查询各进程内存使用情况
adb shell kill [pid] // 杀死一个进程
adb shell ps // 查看进程列表
adb shell ps -x [PID] // 查看指定进程状态
adb shell service list // 查看后台services信息
adb shell cat /proc/meminfo // 查看当前内存占用
adb shell cat /proc/iomem // 查看IO内存分区
adb shell cat /sys/class/net/wlan0/address // 获取mac地址
adb shell cat /proc/cpuinfo // 获取cpu序列号
Screencap
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
input
input keyevent 82 # 菜单事件(MENU)
input keyevent 4 # 回退事件 (BACK)
input text “i_love_beijing” # 输入文字
ime 输入法管理
usage: ime list [-a] [-s]
ime enable ID
ime disable ID
ime set ID
ime list
ime set com.baidu.input_huawei/.ImeService
Android具有prop属性系统,使用getprop和setprop