Using Activity Manager (AM)
Within an adb shell, you can issue commands with the Activity Manager (AM) tool to perform various system actions, such as Start an activity, force-stop A-process, broadcast an intent, modify the device-screen properties, and more. While in a shell, the syntax is:
Am <command>
You can also issue an activity Manager command directly from ADB without entering a remote shell. For example:
ADB shell am start-a Android.intent.action.VIEW
Table 2. Available Activity Manager Commands
 
 
  
   
   Command  |  
   Description  |  
  
 
   
   |     start [options] <INTENT>     |  
      Start an Activity specified by <intent>.    See the specification for <INTENT> arguments.    Options are:   
     
     - -d:enable Debugging. 
  
     - -w:wait for launch to complete. 
  
     - --start-profiler <file>: Start Profiler and send results to <file>. 
  
     - -P <file>: Like--start-profiler, but profiling stops when the app goes idle. 
  
     - -r:repeat the activity launch <COUNT> times. Prior to each repeat, the top activity would be finished. 
  
     - -s:force Stop the target app before starting the activity. 
  
     - --opengl-trace:enable tracing of OpenGL functions. 
  
     - --user <USER_ID> | current:specify which user to run as; if not specified and then run as the current user. 
  
      |  
  
 
   
   StartService [Options] <INTENT>  |  
   Start the Service specified by <intent>. See the specification for <INTENT> arguments. Options are:  
     
     - --user <USER_ID> | Current:specify which user to run as; If not specified and then run as the current user.
  
      |  
  
 
   
   Force-stop <PACKAGE>  |  
   Force stop everything associated with <PACKAGE> (the app's package name).  |  
  
 
   
   Kill [Options] <PACKAGE>  |  
   Kill all processes associated with <PACKAGE> (the app's package name). This command kills only processes that is safe to kill and that would not impact the user experience. Options are:  
     
     - --user <USER_ID> | All | Current:specify user whose processes to kill; All users if not specified.
  
      |  
  
 
   
   Kill-all  |  
   Kill all background processes.  |  
  
 
   
   Broadcast [options] <INTENT>  |  
   Issue a broadcast intent. See the specification for <INTENT> arguments. Options are:  
     
     - [--user <USER_ID> | all | current]: Specify which user to send to; If not specified then the send to all users.
  
      |  
  
 
   
   instrument [Options] <COMPONENT>  |  
      Start monitoring with an instrumentation instance. Typically the target <COMPONENT> is the form <test_package>/<runner_class>.    Options are:   
     
     - -r:print Raw Results (otherwise decode <REPORT_KEY_STREAMRESULT>). Use with [-e perf true] to generate raw output for performance measurements. 
  
     - -E <NAME> <value>: Set argument <NAME> to <value>. For test runners a common form is-e <testrunner_flag> <value>[,<value> ...]. 
  
     - -P <file>: Write profiling data to <file>. 
  
     - -w:wait for instrumentation to finish before returning. Required for test runners. 
  
     - --no-window-animation:turn off window animations while running. 
  
     - --user <USER_ID> | current:specify which user instrumentation runs in; Current user if not specified. 
  
      |  
  
 
   
   Profile Start <PROCESS> <FILE>  |  
   Start Profiler on <process>, write results to <file>.  |  
  
 
   
   Profile Stop <PROCESS>  |  
   Stop Profiler on <process>.  |  
  
 
   
   dumpheap [Options] <PROCESS> <FILE>  |  
   Dump the heap of <process>, write to <file>. Options are:  
     
     - --user [<user_id>|current]: When supplying a process name, specify user of the process to dump; Uses current user if not specified.
  
     - -n:dump native heap instead of managed heap.
  
      |  
  
 
   
   Set-debug-app [Options] <PACKAGE>  |  
   Set application <PACKAGE> to debug. Options are:  
     
     - -w:wait for debugger when application starts.
  
     - --persistent:retain this value.
  
      |  
  
 
   
   Clear-debug-app  |  
   Clear the package previous set for debugging with Set-debug-app.  |  
  
 
   
   Monitor [options]  |  
   Start monitoring for crashes or ANRS. Options are:  
     
     - --gdb:start GD Bserv on the given port at Crash/anr.
  
      |  
  
 
   
   Screen-compat [On|off] <PACKAGE>  |  
   Control screen compatibility mode of <PACKAGE>.  |  
  
 
   
   Display-size [Reset|<wxh>]  |  
   Override emulator/device display size. This command was helpful for testing your app across different screens sizes by mimicking a small screen resolution using a Device with a large-screen, and vice versa. Example: Am Display-size 1280x800  |  
  
 
   
   Display-density <dpi>  |  
   Override emulator/device display density. This command was helpful for testing your app across different screens densities on high-density screen environment using a Low density screens, and vice versa. Example: AM display-density 480  |  
  
 
   
   To-uri <INTENT>  |  
   Print the given intent specification as a URI. See the specification for <INTENT> arguments.  |  
  
 
   
   To-intent-uri <INTENT>  |  
   Print the given intent specification as an Intent:uri. See the specification for <INTENT> arguments.  |  
  
 
  
Using Package Manager (PM)
Within an adb shell, you can issue commandswith the Package Manager (PM) tool to perform actions and queries Onapplication Packages installed on the device. While in a shell, the syntax is:
PM <command>
You can also issue a package managercommand directly from ADB without entering a remote shell. For example:
adb shell pm Uninstall com.example.MyApp
Table 3. Available Package Manager Commands.
 
 
  
   
   Command  |  
   Description  |  
  
 
   
   list packages [Options] <FILTER>  |  
   Prints All packages, optionally-those whose package name contains the text in <filter>. Options:  
     
     - -f:see their associated file.
  
     - -d:filter to only show disabled packages.
  
     - -e:filter to only show enabled packages.
  
     - -s:filter to only show system packages.
  
     - -3:filter to only show third party packages.
  
     - -i:see the installer for the packages.
  
     - -u:also include uninstalled packages.
  
     - --user <user_id>: The user space to query.
  
      |  
  
 
   
   List permission-groups  |  
   Prints all known permission groups.  |  
  
 
   
   List permissions [options] <GROUP>  |  
   Prints All known permissions, optionally only those in <group>. Options:  
     
     - -g:organize by group.
  
     - -f:print all information.
  
     - -s:short Summary.
  
     - -d:only List dangerous permissions.
  
     - -u:list only the permissions users would see.
  
      |  
  
 
   
   List instrumentation  |  
   List all test Packages. Options:  
     
     - -f:list the APK file for the test package.
  
     - <TARGET_PACKAGE>: List Test Packages for the This app.
  
      |  
  
 
   
   List features  |  
   Prints all features of the system.  |  
  
 
   
   List libraries  |  
   Prints all the libraries supported by the current device.  |  
  
 
   
   List users  |  
   Prints all users on the system.  |  
  
 
   
   Path <PACKAGE>  |  
   Print the path to the APK of the given <package>.  |  
  
 
   
   Install [options] <PATH>  |  
   Installs a package (specified by <PATH>) to the system. Options:  
     
     - -l:install the package with forward lock.
  
     - -r:reinstall an exisiting app, keeping it data.
  
     - -t:allow test APKs to be installed.
  
     - -I <installer_package_name>: Specify the INSTALLER package NAME.
  
     - -s:install package on the shared mass storage (such as SDcard).
  
     - -f:install package on the internal system memory.
  
     - -d:allow version code downgrade.
  
      |  
  
 
   
   uninstall [Options] <PACKAGE>  |  
   Removes a package from the system. Options:  
     
     - -k:keep the data and cache directories around after package removal.
  
      |  
  
 
   
   Clear <PACKAGE>  |  
   Deletes all data associated and a package.  |  
  
 
   
   Enable <PACKAGE_OR_COMPONENT>  |  
   Enable the given package or component (written as "Package/class").  |  
  
 
   
   Disable <PACKAGE_OR_COMPONENT>  |  
   Disable the given package or component (written as "Package/class").  |  
  
 
   
   Disable-user [Options] <PACKAGE_OR_COMPONENT>  |  
   Options:  
     
     - --user <user_id>: the user to disable.
  
      |  
  
 
   
   Grant <PACKAGE_PERMISSION>  |  
   Grant permissions to applications. Only optional permissions The application have declared can be granted.  |  
  
 
   
   Revoke <PACKAGE_PERMISSION>  |  
   Revoke permissions to applications. Only optional permissions The application have declared can be revoked.  |  
  
 
   
   Set-install-location <LOCATION>  |  
   Changes the default install location. Location values:  
     
     - 0:auto-let system decide the best location.
  
     - 1:internal-install on Internal device storage.
  
     - 2:external-install on External Media.
  
     Note: This was only intended for debugging; Using this can cause applications to break and the other undesireable behavior.  |  
  
 
   
   Get-install-location  |  
   Returns the current install location. Return values:  
     
     - 0 [Auto]: Lets system decide the best location
  
     - 1 [internal]: Installs on internal device storage
  
     - 2 [external]: Installs on external media
  
      |  
  
 
   
   set-permission-enforced <PERMISSION> [True|false]  |  
   Specifies whether the given permission should be enforced.  |  
  
 
   
   Trim-caches <DESIRED_FREE_SPACE>  |  
   Trim cache files to reach the given free space.  |  
  
 
   
   Create-user <USER_NAME>  |  
   Create a new user with the given <user_name>, printing the new user identifier of the user.  |  
  
 
   
   Remove-user <USER_ID>  |  
   Remove the user with the given <user_identifier>, deleting all data associated with that user  |  
  
 
   
   Get-max-users  |  
   Prints the maximum number of users supported by the device.  |  
  
 
  
ADB Shell am PM usage