19

I am showing the user the Input Method Picker like so and the picker pops up:

InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

im.showInputMethodPicker();

Now if the user dismisses the picker (for example by clicking outside the picker) I want to know that, that happened and do some action (like show a notification for example).

I know that in an Activity I can do the dirty way of checking the focus of the root layout and I know that with the Accessibility permission I can check if that system dialog is focused or not.

The problem is that I am running a service and I need to detect if the IME picker is showing or not even if I am not in my app (a third party app for example or even the Android keyboard settings) and also I find the Accessibility permission a bit confusing for the user therefore I would prefer to not resort to that and find an alternative way.

Is there an alternative way?

Aki K
  • 1,222
  • 1
  • 27
  • 49
  • 2
    I sure hope that this is impossible outside of using the accessibility APIs. Apps should not be able to spy on the foreground UI in other ways. – CommonsWare May 07 '15 at 22:12
  • @CommonsWare on the other hand though we can fairly easily figure out which app is running on the foreground. Because of that I thought that maybe there is a way. – Aki K May 08 '15 at 08:50
  • "on the other hand though we can fairly easily figure out which app is running on the foreground" -- not as easily on 5.0+, and I am working with Google to close another of these privacy and security flaws. – CommonsWare May 08 '15 at 10:23
  • @CommonsWare fair enough. – Aki K May 08 '15 at 11:07

1 Answers1

0

This should be a comment, but i can't comment yet.

You could use xposed to achive that, but that would require a rooted device, and I guess thats out of discussion.

This is a thing the accessibility api is ment for. You already said you don't want to use the dirty way, so I would recommend you to just use said api.

There shouldn't be a way to do this for security concerns (and isn't afaik).

F43nd1r
  • 7,690
  • 3
  • 24
  • 62