MrK
MrK

Reputation: 662

Access all View attributes from InputMethodService

I'm trying to access some attributes from the View that launched my keyboard. For instance if I have the following view in my app:

<EditText
  android:contentDescription="content description"
  android:privateImeOptions="private ime options" />

I can access the privateImeOptions from my InputMethodService like so:

@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
    final String privateImeOptions = info.privateImeOptions;
}

However I cannot access the contentDescription attribute in the same way.

Is there a way I can read specific attributes such as the contentDescription of the View that launched the IME? I only need read access to the attribute, I don't need to change it.

Upvotes: 0

Views: 138

Answers (1)

MrK
MrK

Reputation: 662

The short answer to this is no, there is no way to access the attributes from an InputMethodService

However, there is a solution using an AccessibilityService to read the View attributes, and then pass this information to the InputMethodService.

There's no way to confirm the keyboard and accessibility service Views match, but you can assume that the View in focus is the one that launched the keyboard. To get the View in focus from the accessibility service you can use

final AccessibilityNodeInfo focusedView = findFocus(AccessibilityNodeInfo.FOCUS_INPUT);

It's probably not an ideal solution for most situations but I wanted to document it for anyone else who might find it useful in the future

Upvotes: 0

Related Questions