How to detect the Input Method Picker visibility without the Accessibility permission
Asked Answered
C

1

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?

Contradiction answered 30/4, 2015 at 11:8 Comment(4)
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.Goodhumored
@Goodhumored 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.Contradiction
"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.Goodhumored
@Goodhumored fair enough.Contradiction
T
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).

Transmogrify answered 14/7, 2015 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.