项目中adb shell am 常见用法

am start

C:\Users>adb shell am start
usage: am [subcommand] [options]
usage: am start [-D] [-W] [-P ] [--start-profiler ]
               [--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace]
               [--user  | current] 
       am startservice [--user  | current] 
       am stopservice [--user  | current] 
       am force-stop [--user  | all | current] 
       am kill [--user  | all | current] 
       am kill-all
       am broadcast [--user  | all | current] 
       am instrument [-r] [-e  ] [-p ] [-w]
               [--user  | current]
               [--no-window-animation] [--abi ] 
       am profile start [--user  current] [--sampling INTERVAL]  
       am profile stop [--user  current] []
       am dumpheap [--user  current] [-n]  
       am set-debug-app [-w] [--persistent] 
       am clear-debug-app
       am set-watch-heap  
       am clear-watch-heap
       am monitor [--gdb ]
       am hang [--allow-restart]
       am restart
       am idle-maintenance
       am screen-compat [on|off] 
       am package-importance 
       am to-uri [INTENT]
       am to-intent-uri [INTENT]
       am to-app-uri [INTENT]
       am switch-user 
       am start-user 
       am stop-user [-w] 
       am stack start  
       am stack movetask   [true|false]
       am stack resize  
       am stack split   [INTENT]
       am stack list
       am stack info 
       am task lock 
       am task lock stop
       am task resizeable  [true|false]
       am task resize  
       am get-config
       am set-inactive [--user ]  true|false
       am get-inactive [--user ] 
       am send-trim-memory [--user ] 
               [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]

启动activity

usage: am start [-D] [-W] [-P ] [--start-profiler ]
               [--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace]
               [--user  | current] 
am start: start an Activity.  Options are:
    //开启debug模式
    -D: enable debugging
    
    //等待启动完成
    -W: wait for launch to complete

    //将profiler中的结果输出到指定文件中
    --start-profiler : start profiler and send results to 

    //采样,需和start-profiler一起使用
    --sampling INTERVAL: use sample profiling with INTERVAL microseconds
        between samples (use with --start-profiler)

    //和--start-profiler一样,区别在于,在app进入idle状态时profiler结束
    -P : like above, but profiling stops when app goes idle

    //重复启动Activity,但每次重复启动都会关闭掉最上面的Activity
    -R: repeat the activity launch  times.  Prior to each repeat,
        the top activity will be finished.

    //关闭Activity所属的App进程后再启动Activity
    -S: force stop the target app before starting the activity

    //开启OpenGL tracing
    --opengl-trace: enable tracing of OpenGL functions

    //使用指定的用户来启动activity,如果不输入,则使用当前用户执行
    --user  | current: Specify which user to run as; if not
        specified then run as the current user.

示例:

  • -n 使用组件名方式启动照相机功能
C:\Users>adb shell am start -n com.android.camera/.Camera
Starting: Intent { cmp=com.android.camera/.Camera }
  • -p 先停止目标应用,再启动
C:\Users>adb shell am start -S com.android.camera/.Camera
Stopping: com.android.camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera }
  • -w 等待应用完成启动
C:\Users>adb shell am start -W com.android.camera/.Camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera }
Status: ok
Activity: com.android.camera/.Camera
ThisTime: 295
TotalTime: 295
WaitTime: 314
Complete
  • -a Intent加参数
//打开拨号界面,并传递一个DATA_URI数据给拨号界面
am start -a android.intent.action.CALL -d tel:10086

//加Extra, 键值对
adb shell am start -a com.example.bianji.changedata -e lon 31.23037123456 -e lan 121.4737123456

//给特定号码发送短信
C:\Users>adb shell am start -a android.intent.action.SENDTO -d sms:10086 --es sms_body cxye
Starting: Intent { act=android.intent.action.SENDTO dat=sms:xxxxx (has extras) }
  • 反编译调试
//微信
adb shell am start -D -W -n com.tencent.mm/com.tencent.mm.ui.LauncherUI

//微博
adb shell am start -D -W -n com.sina.weibo/com.sina.weibo.SplashActivity

其他参数 如 CATEGORY、MIME_TYPE再探讨。

service 与 broadcast

启动service与broadcast用法与activity类似

  //toolAPP中两种方法拷贝文字:
  am broadcast -a com.example.copy.text -e "content" "12345678"
  am startservice  -a com.example.copy.text.second -e  "content" "12345678"

INTENT参数:

 specifications include these flags and arguments:
    [-a ] [-d ] [-t ]
    [-c  [-c ] ...]
    [-e|--es   ...]
    [--esn  ...]
    [--ez   ...]
    [--ei   ...]
    [--el   ...]
    [--ef   ...]
    [--eu   ...]
    [--ecn  ]
    [--eia  [, [,)
    [--ela  [, [,)
    [--efa  [, [,)
    [--esa  [, [,; to embed a comma into a string,
         escape it using "\,")
    [--grant-read-uri-permission] [--grant-write-uri-permission]
    [--grant-persistable-uri-permission] [--grant-prefix-uri-permission]
    [--debug-log-resolution] [--exclude-stopped-packages]
    [--include-stopped-packages]
    [--activity-brought-to-front] [--activity-clear-top]
    [--activity-clear-when-task-reset] [--activity-exclude-from-recents]
    [--activity-launched-from-history] [--activity-multiple-task]
    [--activity-no-animation] [--activity-no-history]
    [--activity-no-user-action] [--activity-previous-is-top]
    [--activity-reorder-to-front] [--activity-reset-task-if-needed]
    [--activity-single-top] [--activity-clear-task]
    [--activity-task-on-home]
    [--receiver-registered-only] [--receiver-replace-pending]
    [--selector]
    [ |  | ]

你可能感兴趣的:(项目中adb shell am 常见用法)