1. 获取当前界面的activity
Android7.0之前:
android 7.0之前:
linux:
adb shell dumpsys activity | grep "mFocusedActivity"
windows:
adb shell dumpsys activity | findstr "mFocusedActivity"
Android8.0之后:
android 8.0之后:
Linux:
adb shell dumpsys activity | grep "mResumedActivity"
Windows:
adb shell dumpsys activity | findstr "mResumedActivity"
2、启动APP的指定activity:adb shell am start com.android.settings/com.android.settings.Settings
使用am命令启动某个action:命令格式为:adb shell am start -a -d
adb shell am start -a android.intent.action.DIAL -d tel:10010
直接启动URI:adb shell am start -d dangbeistore://appall
指定action和URI:adb shell am start -a com.sccngitv.dvb.dangbei.action.activity -d dangbeistore://appclass?type=education
常用参数:
-a
: 指定Intent action, 实现原理Intent.setAction();-n
: 指定组件名,格式为{包名}/.{主Activity名},实现原理Intent.setComponent();-d
: 指定Intent data URI-t
: 指定Intent MIME Type-c [-c ] ...]
:指定Intent category,实现原理Intent.addCategory()-p
: 指定包名,实现原理Intent.setPackage();-f
: 添加flags,实现原理Intent.setFlags(int ),紧接着的参数必须是int型;
am start -a android.intent.action.VIEW
am start -n com.yuanhh.app/.MainActivity
am start -d content://contacts/people/1
am start -t image/png
am start -c android.intent.category.APP_CONTACTS
- -a
启动时,要执行的动作,如:android.intent.action.VIEW,我在这里刚开始没有理解他怎么用,网上大部分例子都是:
adb shell am -a android.intent.action.VIEW -d http://www.baidu.com 启动浏览器打开一个网站
其实,还有更一般的用法,就是可以通过这种方式启动我们自己的app,假设我们在我们的app的AndroidManifest.xml文件中的activity标签中加入了
那么我们就可以通过:adb shell am start -a android.intent.action.MY_APP来启动我们的应用了,MY_APP随便取名字,不和系统的内置名字冲突就行了。
- -d
启动时,要传入的URI,如:http://www.baidu.com。到这里,我想我们应该能猜到这个参数的意义了吧,它无非就是在启动我们的activity时,传入URI参数,供app程序分析,并执行对应操作,假设我们的app没有处理这个参数,传进去也没有什么意义。
- -t
摘自别人的文章“我在写android资源管理器(文件浏览器)的时候,希望能在资源管理器的中实现打开文件的操作,此时就需要用到文件的MIME类型。”,这玩意传进去具体怎么用,我也不清楚。用到的时候再研究吧。这个参数
- -n
直接启动一个组件,例如:adb shell am start -n com.example.app/.ExampleActivity
3、清理应用信息:adb shell pm clear com.xxx.yyy
杀掉某个应用进程:adb shell am force-stop com.sccngitv.dvb
adb shell am kill
4、卸载应用:adb uninstall com.xxx.yyy
5、所有应用包名列表:adb shell pm list packages
6、查看进程名称: adb shell ps 或者 adb shell ps com.gala.video 特定:adb shell ps | findstr tencent
7、dump内存: adb shell am dumpheap com.gala.video /sdcard/dddd05.hprof 然后再adb pull /sdcard/dddd05.hprof 将这个文件放在android_sdk/platform-tools/目录下,在命令行中执行 hprof-conv dddd05.hprof newddd05.hprof
8、设置某个SharedPreference的属性以及获取属性值:
adb root adb shell setprop scn.debug.ouside.region true
getprop persist.sys.device.id
9、删除系统应用apk,删除apk文件后,自动卸载: adb remount adb shell cd system/app ls //所有apk文件 rm -r XXX_YYY.apk
10、截屏: adb shell screencap -p /sdcard/01.png adb pull /sdcard/01.png
11、adb输入信息
C:\Users\buder_cp>adb shell shell@Hi3798MV300:/ $ input text "d"