I found the solution:
InputMethodService ims;
...
Dialog dialog = ims.getWindow();
Window window = dialog.getWindow();
or simply:
Window window = ims.getWindow().getWindow();
(This works with an InputMethodService and is not necessarily applicable to other Services.)