+ Reply to Thread
Results 1 to 2 of 2

Thread: How to listen to hardware key events ?

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    15

    How to listen to hardware key events ?

    I dont want to allow user to go back screen and want to handle hardware back event.I have tried many code snippets from web but didnt worked please give a head shot solution if possible.

  2. #2
    Junior Member
    Join Date
    Aug 2012
    Posts
    15
    First of all android does not cares about hardware or software events They are all just events which get generated and are handled by a callback function.

    NOTE:Key Events cannot be handled in service.

    In your activity override the method onKeyDown()

    Code:
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
          
         if (keyCode == KeyEvent.KEYCODE_BACK){
        	
        	 return true;
          }
         
         return super.onKeyDown(keyCode, event);
    }
    KeyEvent is used to listen different keys.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts