Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle hardware search button android?

Tags:

android

I am new to android, I have a small doubt regarding how to handle the hardware Keyboard and if I click the search button in any part of my application it should be handled means I need to pass the intent of search activity?

How I can reach this goal.

like image 216
NikhilReddy Avatar asked Nov 02 '11 04:11

NikhilReddy


People also ask

How to handle hardware back button in Android?

The hardware back button is found on most Android devices. In native applications it can be used to close modals, navigate to the previous view, exit an app, and more. By default in Ionic, when the back button is pressed, the current view will be popped off the navigation stack, and the previous view will be displayed.

What is hardware buttons in Android?

OS buttons are reserved for system actions: turning power on and off, and launching apps. All Wear OS watches have a power button and a launcher button.


2 Answers

Try this,

  @Override
 public boolean onSearchRequested() {
     // your stuff here
     return false; 
 }
like image 173
user370305 Avatar answered Oct 26 '22 08:10

user370305


It will also trigger onKeyDown with a keyCode of KeyEvent.KEYCODE_SEARCH before calling onSearchRequested as stated above

like image 33
FrinkTheBrave Avatar answered Oct 26 '22 09:10

FrinkTheBrave