android - 如何在 android 中启动最近的应用程序菜单?

标签 android android-intent

我想启动显示最近使用的应用程序的菜单。

我尝试在按下按钮时查看 logcat,希望有一些我可以启动的 Intent ,但没有成功。

我知道在某些手机上它是一个专用按钮,也可以通过长按主页按钮来实现。有什么方法可以以编程方式启动它吗?

编辑:更新标题更准确

最佳答案

当您按下“最近的应用程序”按钮时,logcat 将输出以下消息:

568-716/system_process I/ActivityManager﹕ START u0 {act=com.android.systemui.recent.action.TOGGLE_RECENTS flg=0x10800000 cmp=com.android.systemui/.recent.RecentsActivity} from pid 627
    --------- beginning of /dev/log/main
568-582/system_process I/ActivityManager﹕ Displayed com.android.systemui/.recent.RecentsActivity: +215ms

因此,我们可以通过编程方式模拟此操作。 (不要忘记将标志设置为 0x10800000):

Intent intent = new Intent ("com.android.systemui.recent.action.TOGGLE_RECENTS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.setComponent(new ComponentName("com.android.systemui", "com.android.systemui.recent.RecentsActivity"));
startActivity (intent);

关于RecentsActivity的更多信息,请阅读源码here .

关于android - 如何在 android 中启动最近的应用程序菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12344738/

相关文章:

android - 当我在 Android Jetpack Compose 中使用 Remember 时,为什么无法获得相同的类实例?

android - 在 ListView 中默认选择一行并突出显示所选行 Android

android - 我的 Android 应用程序有一个确实运行但未显示在服务列表中的 Intent 服务

java - Android - 带有待处理 Intent 的多个警报,如何确定正在调用哪个 Intent ?

android - tabhost 安卓

android - Eclipse 不识别 android SDK

android - 无法将文件上传到 WebView

Android xml 文件错误

Android camera2 闪光灯在自动闪光模式下在弱光条件下不闪光

java - 防病毒软件如何以编程方式扫描已安装的 android 应用程序的代码(没有 root 权限)?