Presenting a keyboard or a popup menu with a search field requires you to implement the KeyboardListener
. Note that the initialText
in the keyboard case often acts as "placeholder text" and not as true initial text.
You should present a keyboard to users when your app contains a "search" field. For example, in a music player app, you may want to give the user a way to search for a song or album. A keyboard could also be useful in an app that displays nearby points of interest, or in other situations.
Keyboards are unavailable for use in many countries when the driver is distracted. This is often when the vehicle is moving above a certain speed, such as 5 miles per hour. This will be automatically managed by the system. Your keyboard may be disabled or an error returned if the driver is distracted.
int cancelId = sdlManager.getScreenManager().presentKeyboard("Initial text", null, keyboardListener);
Using the KeyboardListener
involves implementing five methods:
KeyboardListener keyboardListener = new KeyboardListener() { @Override public void onUserDidSubmitInput(String inputText, KeyboardEvent event) { switch (event) { case ENTRY_VOICE: // The user decided to start voice input, you should start an AudioPassThru session if supported break; case ENTRY_SUBMITTED: // The user submitted some text with the keyboard break; default: break; } } @Override public void onKeyboardDidAbortWithReason(KeyboardEvent event) { switch (event) { case ENTRY_CANCELLED: // The user cancelled the keyboard interaction break; case ENTRY_ABORTED: // The system aborted the keyboard interaction break; default: break; } } @Override public void updateAutocompleteWithInput(String currentInputText, KeyboardAutocompleteCompletionListener keyboardAutocompleteCompletionListener) { // Check the input text and return a list of autocomplete results keyboardAutocompleteCompletionListener.onUpdatedAutoCompleteList(updatedAutoCompleteList); } @Override public void updateCharacterSetWithInput(String currentInputText, KeyboardCharacterSetCompletionListener keyboardCharacterSetCompletionListener) { // Check the input text and return a set of characters to allow the user to enter } @Override public void onKeyboardDidSendEvent(KeyboardEvent event, String currentInputText) { // This is sent upon every event, such as keypresses, cancellations, and aborting } };
You can dismiss a displayed keyboard before the timeout has elapsed by sending a CancelInteraction
request. If you presented the keyboard using the screen manager, you can dismiss the choice set by calling dismissKeyboard
with the cancelID
that was returned (if one was returned) when presenting.
If connected to older head units that do not support this feature, the cancel request will be ignored, and the keyboard will persist on the screen until the timeout has elapsed or the user dismisses it by making a selection.
sdlManager.getScreenManager().dismissKeyboard(cancelId);
If you don't want to use the ScreenManager
, you can do this manually using the PerformInteraction
RPC request. As this is no longer a recommended course of action, we will leave it to you to figure out how to manually do it.