adb detailed tutorial (4) - use adb to start applications, close applications, clear application data, and obtain the list of installed applications on the device

  • adb is a very important debugging tool for Android mobile terminals.
  • This article introduces commonly used adb commands


(I have uploaded the adb installation package to the network disk. You can directly search the official account [Essential Skills for Software Testing] or slide to the bottom of the article, click on the official account card to scan the QR code, and go to Follow to receive it.)

1. Start the application: adb shell am start

  • The application can be started directly through the adb command, but you need to know the full path of the application's startup activity.
  • The command template is as follows:
    adb shell am start {
          
          包名}/{
          
          启动activity}
    

If you don’t know the startup activity of your application, you can try the following method:

  1. Use the adb command "adb logcat -c" to clear the logs
  2. Then use the adb command "adb logcat ActivityManager:I *:S", which will print out the activity information running on the device.
  3. Start application
  4. Because the command to clear the log has been executed before, it is easy to find the first activity started by the application.
    Insert image description here
  • After you have the package name and the startup activity, you can run the command to start the application:
    adb shell am start com.tencent.qqmusic/com.tencent.qqmusic.activity.AppStarterActivity
    
    Insert image description here

2. Use the browser to open the specified URL: adb shell am start

  • You can use the adb command to command the device to open the specified URL through the browser.
    adb shell am start -a android.intent.action.VIEW -d {
          
          URL}
    
  • Example:
    adb shell am start -a android.intent.action.VIEW -d https://www.csdn.net/
    
    • The result will be displayed after successInsert image description here

3. Kill the application process adb shell am force-stop/adb shell am kill

  • You can kill the application process on the device through adb command
  1. Kill the process of the specified application
    adb shell am force-stop {
          
          包名}
    
  2. Kill all background processes.
    adb shell am kill-all
    
  • Example:
    adb shell am force-stop com.tencent.qqmusic
    
    • This command does not display results, but if the specified application is running on the device at this time, you can see that the application has been closed.
      Insert image description here

4. Delete all application data: adb shell pm clear package

  • You can delete all application data through the adb command:
    adb shell pm clear {
          
          包名}
    
  • Example
    adb shell pm clear com.tencent.qqmusic
    
    • After success, "Success" will be printed.Insert image description here

5. Get the list of installed applications on the device: adb shell pm list package

  • You can obtain the list of installed applications on the device through the adb command:
    adb shell pm list packages {
          
          选项} {
          
          关键字} 
    
  • {options} and {keywords} are optional
  • If {keyword} is filled in, applications whose package names contain keywords will be output.
  • {Options} specifically include the following:
    • -f: View associated files.
    • -d: Filter to show only deactivated packages.
    • -e: Filter to show only enabled packages.
    • -s: Filter to show only system packages.
    • -3: Filter to show only third-party packages.
    • -i: View the package installer.
    • -u: Include uninstalled packages.
    • –user user_id: The user space to be queried.
  • Example:
    • Search by keyword
      adb shell pm list packages samsung
      
    • The printed application list all contains the keyword "samsung"Insert image description here

Appendix: [adb detailed tutorial] series of articles table of contents

adb detailed tutorial (1) - download, installation and environment variable configuration
adb detailed tutorial (2) - enable mobile developer mode and connect Android devices through adb< a i=2>adb detailed tutorial (3) - Use adb to install and uninstall app ————————————————————— ——————————


I have uploaded the adb installation package to the public account of the same name of the blog I run [Essential Skills for Software Testing]. The public will also upload test-related information from time to time and can collect it if necessary.

If necessary, please click on the QR code below the article to get it~Insert image description here

Guess you like

Origin blog.csdn.net/weixin_40883833/article/details/133623434