更改 getRecentTasks 的结果
我有一个专为工作场所中的平板电脑设计的应用程序,其中许多人将使用相机作为日常工作的一部分。虽然主管离开应用程序是适当且必要的,但其他人应该很难意外地这样做。然而,长按主页键很容易不小心发生。我自己做过。这会显示最近任务的列表;用户可以点击其中任何一个,然后他们就会迷路,因为其中一些并不像普通智能手机用户那么复杂。
您可以通过编程方式通过 getRecentTasks 检索此列表。我的问题是如何从该列表中删除除最近的任务(我的)之外的所有任务,将长度减少到只有一个元素,或者更改列出的任务以指向我的应用程序。我知道这是可能的:Toddler Lock 做到了。
我的第一次尝试是修改返回的意图,希望它们通过引用传递。没有这样的运气。还有其他想法吗?
(我不是在谈论短按主页键。我已经想出了这一点,部分基于这里找到的东西。)
I have an app designed for a tablet in a workplace setting where a number of people will use the camera as part of their routine. While it's appropriate and necessary for a supervisor to leave the app, it should be difficult for other people to accidentally do so. However, a long press of the home key is pretty easy to do accidentally. I've done it myself. That brings up a list of recent tasks; the user can tap any one of them and they're lost, since some of them aren't as sophisticated as your average smartphone owner.
Programmatically you can retrieve this list via getRecentTasks. My question is how I can remove all but the most recent task (mine) from that list, reduce the length to just one element, or change the listed tasks to point back at my application. I know this is possible: Toddler Lock does it.
My first attempt was to modify the intents returned, in hopes they were passed by reference. No such luck. Any other ideas?
(I'm not talking about a short press of the home key. I already figured that one out, partially based on things found here.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢《幼儿锁》的作者,我曾与他讨论过这个问题。引入的错误完全是我的。
在清单中创建一个禁用的活动,其关联性等于空字符串。在您的程序中,启用它,然后使用标记为 FLAG_ACTIVITY_NEW_TASK 的意图启动它。会在最近的活动中体现出来。禁用该任务,它就会从显示屏上消失。
做足够的这些,你就会淹没最近的活动显示。如果它有办法返回比您的虚拟活动更多的活动,则用户将能够退出您的程序。
确保退出时禁用这些任务,并确保如果您从最近的活动中选择这些任务之一,您的程序会执行合理的操作。
这是我的清单中两个任务的示例:
Credit goes to the author of Toddler Lock, with whom I spoke about the issue. Errors introduced are entirely mine.
Create within your manifest a disabled activity with affinity equal to the empty string. In your program, enable it and then start it up using an intent flagged FLAG_ACTIVITY_NEW_TASK. It will show up in the recent activities. Disable the task and it disappears from the display.
Make enough of these and you flood the recent activities display. If it has a way to go back more activities than you have dummy activities the user will be able to get out of your program.
Make sure you disable the tasks when you exit, and make sure that if you select one of those tasks from recent activities your program does something reasonable.
Here's an example of two of the tasks in my manifest:
您无法通过应用程序执行此操作。您需要构建具有您想要的行为的自定义系统映像。
You can't do this from an application. You would need to build a custom system image with the behavior you want.