Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android "adb shell input keyevent KEYCODE_SEARCH" Not working

I want to fire KEYCODE_SEARCH event using ADB in my code. When i execute this command i am unable to see any action in keyboard. But If i give "adb shell input keyevent KEYCODE_1" it is working perfectly. Please give me any solution to fire search event using ADB.

And My current code is like.

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            performSearch();
            return true;
        }
        return false;
    }
});


<EditText android:imeOptions="actionSearch" 
    android:inputType="text"/>

Thanks.

like image 936
Santhi Bharath Avatar asked Apr 13 '15 03:04

Santhi Bharath


Video Answer


1 Answers

The setting android:imeOptions="actionSearch" doesn't enables your edit text to receive KEYCODE_SEARCH event.

As described on Android reference:

android:imeOptions
Additional features you can enable in an IME associated with an editor to improve the integration with your application. The constants here correspond to those defined by imeOptions.

If you want to receive KEYCODE_SEARCH sent from ADB you need to override onKeyDown in your Activity and manually call onEditorAction

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_SEARCH){
        editText.onEditorAction(EditorInfo.IME_ACTION_SEARCH);
        return true;
    }else{
        return super.onKeyDown(keyCode, event);
    }
}

Please note that the other apps don't fire the search when KEYCODE_SEARCH event is sent, they simply give focus to the search box

like image 90
Mattia Maestrini Avatar answered Sep 17 '22 18:09

Mattia Maestrini