我需要开发一个应用程序来找到所有可见的应用程序(前景和/或背景)并尽可能多地关闭。我尝试使用以下代码:
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");
}
}
但这对解决问题没有多大帮助。谁能建议我可以用什么来实现这一点?