0 votes
by (240 points)

Hello,

I would like to call the Home button or other keys from my java code, as i have done to pause a video in the pico launcher.
Is there somewhere a list of actions that I can then use to send a broadcast ?

Thank you.

2 Answers

0 votes
by (55.5k points)

Hi,could you please describe what's your meaning of " pause a video in the pico launcher ",is it related to any buttons?According to our understanding, you want to simulate the triggering of a button. This means that even if you did not press the button, you can use java code to run the logic of the button. Is it right?Could you describe it more accurately for us.

Or you just want to monitor button presses and then run some logic.If so, you can refer to this document. And the corresponding key value is here.

by (240 points)

Hello,

Thank you for your answer.
"This means that even if you did not press the button, you can use java code to run the logic of the button" : Yes that is exactly what I would like to do. I used something similar to pause a video with this code :
getApplicationContext().sendBroadcast(new Intent("com.picovr.wing.player.playorpause"));

If something similar is possible for key functions it would be great.

+1 vote
by (1.1k points)
edited by

Hi,

I remember using the adb command is a good way to simulate keys down:

adb shell input keyevent KEYCODE
by (240 points)

Hello,

Thanks for the answer, I guess it is not optimal but could work if I manage to call command lines from my code. However, do you happen to have a list for the keycodes ? Couldn't figure out what to use.
Thank you =)

by (1.1k points)

Hi,

I think this is helpful for you:
https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_HOME

I tested it with my device and it can simulate the home button press with this command:

adb shell input keyevent KEYCODE_HOME

or

adb shell input keyevent 3
...