0

我需要开发一个应用程序来找到所有可见的应用程序(前景和/或背景)并尽可能多地关闭。我尝试使用以下代码:

ApplicationPermissionsManager appPermissionsManager = ApplicationPermissionsManager.getInstance();

ApplicationPermissions appPermissions = appPermissionsManager.getApplicationPermissions();

if (ApplicationPermissions.VALUE_ALLOW == appPermissions.getPermissio(ApplicationPermissions.PERMISSION_INPUT_SIMULATION)) {
try {
EventInjector.KeyCodeEvent pressKey = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, ((char) Keypad.KEY_ESCAPE), 0);

EventInjector.KeyCodeEvent releaseKey = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP, ((char) Keypad.KEY_ESCAPE), 0);

EventInjector.invokeEvent(pressKey);
EventInjector.invokeEvent(releaseKey);

} catch (Exception e) {
System.out.println("\n\n >>>>>> Block App Excep Thread 6 : " + e.toString() + "\n");
}
}

但这对解决问题没有多大帮助。谁能建议我可以用什么来实现这一点?

4

2 回答 2

0

我最近为同一任务开发了一个演示。

我使用与你在这里给出的相同的代码......你能详细告诉我,你的代码的哪一部分你面临问题......或者在这里提供你的代码。

您可以在以下位置找到更多详细信息: 链接 1

并在: 链接2

我会推荐一个连续运行的线程,它只会“休眠”一秒钟,然后检查...当前的前台应用程序,是否要阻止它。可能 Timer 任务会增加您的应用程序的负载....如果您使用线程,您可以轻松地阻止/暂停其处理,直到它关闭当前的前台本机应用程序,但在 TimerTask 的情况下会很困难。

于 2012-06-20T11:44:04.110 回答
0

使用System.exit(0);. 我以前用过它,它工作。

于 2012-06-19T20:03:04.140 回答