ADB:如何通过 ADB 一行命令完全点击/关闭最近使用的应用程序

问题描述 投票:0回答:7

我尝试了多个命令从应用程序切换器关闭应用程序,但没有成功。我什至不知道是否有任何 adb 命令可以持续从应用程序切换器关闭应用程序。我在谷歌上搜索了同样的内容,甚至浏览了Android,但没有运气。 有谁知道这个情况,如何解决? 请提出我们宝贵的意见。 预先感谢

android adb calabash calabash-android
7个回答
16
投票

最后,当我尝试组合多个命令时,我得到了答案:

  1. 打开应用程序切换器

    adb shell input keyevent KEYCODE_APP_SWITCH
    
  2. 在应用程序切换器中选择或导航到下一个应用程序

    adb shell input keyevent 20
    ...
    

    (对列表中的每个应用程序再次运行上述命令)

  3. 从打开的应用程序列表中删除该应用程序

    adb shell input keyevent DEL
    

您已完成:-) 该应用程序已从您打开的应用程序列表中消失。


3
投票
  1. 获取堆栈ID
    adb shell dumpsys activity recents

##########结果示例RecentTask 0

RecentTaskInfo #0:
    id=170 userId=0 hasTask=true lastActiveTime=102664977
    baseIntent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x
10200000 cmp=com.android.vending/.AssetBrowserActivity }
    baseActivity={com.android.vending/com.android.vending.AssetBrowserActivity}
    topActivity={com.android.vending/com.google.android.finsky.activities.MainActivity}
    origActivity={com.android.vending/com.android.vending.AssetBrowserActivity}
    realActivity={com.android.vending/com.google.android.finsky.activities.MainActivity}
    isExcluded=false activityType=standard windowingMode=fullscreen supportsSplitScreenMultiWindow=t
rue supportsMultiWindow=true
    taskDescription { colorBackground=#fffafafa colorPrimary=#ffffffff iconRes=/0 iconBitmap=false r
esizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION minWidth=-1 minHeight=-1 colorBackgroundFloating=#f
fffffff }
    lastSnapshotData { taskSize=Point(1080, 2400) contentInsets=Rect(0, 91 - 0, 126) bufferSize=Poin
t(1080, 2400) }
  1. 删除堆栈 ID 170(Play 商店)
    adb shell am stack remove 170

2
投票

安卓5.0及以上

打开最近使用的应用程序

adb shell 输入按键事件 KEYCODE_APP_SWITCH

选择应用程序

adb shell 输入按键事件 KEYCODE_DPAD_DOWN

从最近的应用程序中清除

adb shell 输入 keyevent DEL


2
投票

感谢@rilwan 的回答,以下命令对我有用: 首先进入adb shell然后执行:

$ adb shell
$ input keyevent KEYCODE_APP_SWITCH && input swipe 522 1647 522 90

或立即执行

$ adb shell input keyevent KEYCODE_APP_SWITCH && input swipe 522 1647 522 90

0
投票

这里有一些提示-

  1. 打开最近使用的应用程序-

adb shell 输入按键事件 KEYCODE_APP_SWITCHER

  1. 点击
    cross X 
    close all
    。根据您的系统 UI,您需要导航到它并按 Enter 键。 对于我来说,下面的方法有效,您可以使用
    up,down,tab
    KEYEVENTs 找到适合您设备的内容。

adb shell 输入按键事件 KEYCODE_DPAD_DOWN

adb shell 输入按键事件 KEYCODE_ENTER


0
投票
#get apps
dumpsys window windows | grep -P 'topApp.* u0 ([^/]+)' | grep -P '(?<= u0 )[^/]+' | xargs -l am force-stop

0
投票

我编写了 shell 脚本,它将关闭所有最近使用的应用程序。

#!/bin/bash

# When this is executed:
# ```
# adb shell dumpsys activity recents | grep 'Recent #0'
# ```
#
# The output will be like this:
# ```
#   * Recent #0: Task{46c88ca #115 type=standard A=10162:com.lifemd.care.stage}
#   * Recent #1: Task{cb4f5ae #111 type=home I=com.google.android.apps.nexuslauncher/.NexusLauncherActivity}
# ```
#
# The output is filtered to get only `standard` type tasks and then their IDs are extracted.
# The IDs are then used to close the recent apps.
close_all_recent_apps() {
  # Extract the IDs of all recent apps
  local tasks
  tasks=$(adb shell dumpsys activity recents | grep "Recent #" | grep "type=standard")


  # Split the output into an array
  IFS=$'\n' read -rd '' -a tasks <<<"$tasks"

  # Close each recent app
  for task in "${tasks[@]}"; do
    echo "TACO: $task"
    local task_id
    task_id=$(echo "$task" | sed -n 's/.*#\([0-9]*\).*/\1/p')
    echo "Closing the recent app with ID: $task_id"
    adb shell am stack remove "$task_id"
  done
}

close_all_recent_apps
© www.soinside.com 2019 - 2024. All rights reserved.