android custom soft keyboard intercepting ime_action

576 Views Asked by At

I'm currently making a soft keyboard of my own in android and having a hard time getting the ime action selected - (IME_ACTION_SEARCH or IME_ACTION_DONE etc.).

For instance, if an user enters google search than the action button should be a search button and if it's a sms then it'll be a line break. How can I differ between them?

I've tried looking for it in the with no luck.

onCreateInputView(){}

Any help is appreciated.

1

There are 1 best solutions below

1
On BEST ANSWER

You can call getCurrentInputEditorInfo on your InputMethodService. Then you can inspect the EditorInfo's imeOptions property.

int imeOptions = mInputMethodService.getCurrentInputEditorInfo().imeOptions;
switch (imeOptions&EditorInfo.IME_MASK_ACTION) {
            case EditorInfo.IME_ACTION_NONE:
                // None
            case EditorInfo.IME_ACTION_GO:
                // Go
            case EditorInfo.IME_ACTION_SEARCH:
                // Serach
            case EditorInfo.IME_ACTION_SEND:
                // Send
            case EditorInfo.IME_ACTION_NEXT:
                // Next
            case EditorInfo.IME_ACTION_DONE:
                // Done
        }