LongPress on Android Back Button and Home Button


In the application I’m testing, the developers have a way to access the debug page in the app. To do so, I need to long press the Android Back button. I see there is a mobile event called longPress in the documentation. Tried using this event with AndroidKeycode.BACK and this returned an error about this event not being implemented yet.

Is there any other way to long press the Android buttons.



Your Appium client ought to have a method to long press on a keycode. In Python it is driver. long_press_keycode(4)

I’m working with Java. Looks like this function doesn’t exist in the Java-Client. There’s long_press functions but the parameters are x,y coordinates/webelement.

Hi guys,
I’m trying to use Java long tap on appium server 1.4.13 and look like it’s work same as usual pressKeyCode method.
At AndroidDriver.class
public void pressKeyCode(int key) {
this.execute(“pressKeyCode”, getCommandImmutableMap(“keycode”, Integer.valueOf(key)));
public void longPressKeyCode(int key) {
this.execute(“pressKeyCode”, getCommandImmutableMap(“keycode”, Integer.valueOf(key)));

Will it fixed?
Really need this method to test launching activity after long tap on home button.



Do you want to launch any background app. What is the need of long press of home button?

No, our app is launching after long press on Home button. We need to test this scenario.

I too tried for the same but i did not get.But for me the solution is recent apps.

Yes, it’s one of entry point for us too, but if u have a few points, u need to test them all. In some cases it can fail on launch.

Hi @Wikkjaz, @nagendraq

If you are using devices kitkat or newer, this command should work to simulate longpress on home button

adb shell input keyevent --longpress 3
1 Like


Thank You very much Telmo. Its working very fine in kitkat.

Thank you, Telmo! Working for me.