Detecting When Android Keyboard Is Cancelled By Back Key

Hi, I am using native text fields to make a login form. When the user selects a field, I use corona to move that field to the top of the screen, but now I am having a problem:

When the user presses submit, I can move the field over to its starting position, but if the user presses the android back key, the keyboard hides, and the field stays on top.

I have tried using the “key” event listener, but that back event is used by the keyboard, and can’t be detected.

Neither “key” nor “userInput” send any event when the user closes the keyboard by using the back key.

I know that I can use setKeyboardFocus(nil) to hide the keyboard, but is there any getKeyboardFocus() or similar to know if the user has hidden the keyboard manually?

I’d like to know the answer to this question too.  On Nexus 4, tapping on “Done” works like a charm, but how do we handle  Android key?

 

With iOS version, I move the textField up when the keyboard appears and bring it down after the keyboard is removed from the screen.  

 

With Android version running on Nexus 4, the keyboard completely covers the entire screen, so I don’t even need to move the textField up.  So I was almost ready to add a separate handling for Android version.  But then, I haven’t tested the Android version on other Android devices.  Does keyboard work the same way on all Android device (i.e., cover up the entire screen), or does it depend on device?  In case it behaves vastly different between devices, I’ve been reluctant about adding the switch between iOS and Android version.

 

@dittophantassy, what device are you using to test it, and how does the keyboard appear on screen?

 

Naomi

I am testing it on an acer tablet and the default keyboard (android supports dozens of custom keyboards) covers like a third of the screen on landscape, and I still can’t detect when the user closes manually the keyboard.

Tthe only solution I found is to put a touch sensor on all the screen, and if the user presses anywhere after clossing the keyboard, the field returns to its place, but it still looks wrong.

Thanks for letting me know, @dittophantassy.  Sounds like I really should check this on some tablet devices.  Meanwhile, if there’s a way to handle Android key more effectively, I hope someone will let us know.

 

Naomi

I’d like to know the answer to this question too.  On Nexus 4, tapping on “Done” works like a charm, but how do we handle  Android key?

 

With iOS version, I move the textField up when the keyboard appears and bring it down after the keyboard is removed from the screen.  

 

With Android version running on Nexus 4, the keyboard completely covers the entire screen, so I don’t even need to move the textField up.  So I was almost ready to add a separate handling for Android version.  But then, I haven’t tested the Android version on other Android devices.  Does keyboard work the same way on all Android device (i.e., cover up the entire screen), or does it depend on device?  In case it behaves vastly different between devices, I’ve been reluctant about adding the switch between iOS and Android version.

 

@dittophantassy, what device are you using to test it, and how does the keyboard appear on screen?

 

Naomi

I am testing it on an acer tablet and the default keyboard (android supports dozens of custom keyboards) covers like a third of the screen on landscape, and I still can’t detect when the user closes manually the keyboard.

Tthe only solution I found is to put a touch sensor on all the screen, and if the user presses anywhere after clossing the keyboard, the field returns to its place, but it still looks wrong.

Thanks for letting me know, @dittophantassy.  Sounds like I really should check this on some tablet devices.  Meanwhile, if there’s a way to handle Android key more effectively, I hope someone will let us know.

 

Naomi

I have the same problem.

I have the same problem.

Google Android SDK had solution, but it still need Coron Lab to implement it in corona sdk.

=============================================================================

public boolean onKeyPreIme (int keyCode, KeyEvent event)

Added in API level 3

Handle a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application’s UI instead of allowing the IME to see it and close itself.

Parameters keyCode The value in event.getKeyCode(). event Description of the key event.

Returns

  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

Have you looked at this tutorial:
 

http://coronalabs.com/blog/2013/03/26/androidizing-your-mobile-app/

Rob

Hi Rob:

Yes, I had tried this before, and I failed to get all necessary key response, the major issue for detect keyboard dismissing is same as following topic, I will keep discussing in that topic. 

http://forums.coronalabs.com/topic/39512-no-event-was-triggered-when-the-dismiss-the-keyboard-button-was-pressed-on-nexus-7/

Best Regards,

Farmer

Our Android engineers have responded to this question many times.  They can’t capture the keyboard dismissal button.  They can capture, Back, VolumeUp and VolumeDown.  I suspect the method listed above is how we are capturing those keys already.  I’ve asked them to look at it what you’ve posted just in case.  Perhaps we are running at a layer that we can’t get that information. 

Rob

Hi Rob:

I understand we can get “back” “volume up” “volume down” event by [[Runtime:addEventListener( “key”, onKeyEvent )]], but that is not enough.

I understand Corona SDK is implement by OPENGL over on Android OS. That’s the reason why I think corona SDK should can receive all the signal from Android. For those native Android app written in Java, which can get the response with some special key (such as “V”), I have the confidence that corona sdk should can do that also.

For another key response issue, please check the attached image captured from HTC Desire V, the “square key” (red circle) is placed in soft keyboard, I think there should be some event or value returned to system, but corona sdk didn’t send it back to us.

[sharedmedia=core:attachments:2415]

I am not sure which android api was used in corona sdk to receive key event, but according android docs or other java android app, there are some signal really existed to solve keyboard dismiss, keyboard height etc.

Thanks for your kindly support.

Farmer

Google Android SDK had solution, but it still need Coron Lab to implement it in corona sdk.

=============================================================================

public boolean onKeyPreIme (int keyCode, KeyEvent event)

Added in API level 3

Handle a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application’s UI instead of allowing the IME to see it and close itself.

Parameters keyCode The value in event.getKeyCode(). event Description of the key event.

Returns

  • If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

Have you looked at this tutorial:
 

http://coronalabs.com/blog/2013/03/26/androidizing-your-mobile-app/

Rob

Hi Rob:

Yes, I had tried this before, and I failed to get all necessary key response, the major issue for detect keyboard dismissing is same as following topic, I will keep discussing in that topic. 

http://forums.coronalabs.com/topic/39512-no-event-was-triggered-when-the-dismiss-the-keyboard-button-was-pressed-on-nexus-7/

Best Regards,

Farmer

Our Android engineers have responded to this question many times.  They can’t capture the keyboard dismissal button.  They can capture, Back, VolumeUp and VolumeDown.  I suspect the method listed above is how we are capturing those keys already.  I’ve asked them to look at it what you’ve posted just in case.  Perhaps we are running at a layer that we can’t get that information. 

Rob

Hi Rob:

I understand we can get “back” “volume up” “volume down” event by [[Runtime:addEventListener( “key”, onKeyEvent )]], but that is not enough.

I understand Corona SDK is implement by OPENGL over on Android OS. That’s the reason why I think corona SDK should can receive all the signal from Android. For those native Android app written in Java, which can get the response with some special key (such as “V”), I have the confidence that corona sdk should can do that also.

For another key response issue, please check the attached image captured from HTC Desire V, the “square key” (red circle) is placed in soft keyboard, I think there should be some event or value returned to system, but corona sdk didn’t send it back to us.

[sharedmedia=core:attachments:2415]

I am not sure which android api was used in corona sdk to receive key event, but according android docs or other java android app, there are some signal really existed to solve keyboard dismiss, keyboard height etc.

Thanks for your kindly support.

Farmer

Hi Rob and All,

Is this problem resolved yet??
Can keyboard dismiss event by android back button for now? because i am also moving my field above from keyboard so that they can not hide behind keyboard. And i give transition back to previous place to fields on screen touch…

But when i press device back button, it closes keyboard but my scene remains there…

I cannot find any event of keyboard dismiss or anything like this to get me help to achieve this…

Thanx in advance
Sajid Zeb