Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] KeyEvent Trigger not working

OP aeppacher

17th March 2014, 08:15 PM   |  #1  
aeppacher's Avatar
OP Senior Member
Thanks Meter: 739
 
632 posts
Join Date:Joined: Apr 2012
In my currentactivity I have been trying to trigger a keyevent using the following code:

Code:
this.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
but when this part of the code runs nothing happens and it doesn't simulate the back button being pressed. Before people recommend finish() or onBackPressed(), they will not work for my required implementation because I need both the home button and the recents button to be triggered too and that apparently can be done by triggering keyevents.

Anyone know whats going wrong here?

EDIT: I added:

Code:
this.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK));
to release the key and this worked but it wont work for KeyEvent.KEYCODE_HOME or KeyEvent.KEYCODE_APP_SWITCH. Do I need to declare permissions in my manifest to perform these?
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes