I am trying to detect showKeyboard
and hidekeyboard
events on phonegap. For that purpose, on deviceready
event I placed following code
Using ionic-plugin-keyboard, the events native.keyboardshow
and native.keyboardhide
are fired, even in fullscreen / immersive Mode:
Example Code:
document.addEventListener('deviceready',
function(){
// disable immersive mode on Android when keyboard is shown
try {
if (cordova.platformId == 'android') {
AndroidFullScreen.immersiveMode(false, false);
window.addEventListener('native.keyboardshow', function (e) {
AndroidFullScreen.showSystemUI(false, false);
});
window.addEventListener('native.keyboardhide', function (e) {
AndroidFullScreen.immersiveMode(false, false);
});
}
} catch (error) {
console.log('deviceready - ' + error);
}
}, false);
Apparently showkeyboard
/ hidekeyboard
events WILL NOT fire when you are running your app in a full-screen mode (eg. no status bar at the top) because the screen size doesn't change when the keyboard pops-up.
https://issues.apache.org/jira/browse/CB-392
Try this first let's see if it narrows down your problem to the event firing or the function it tries to call when the event fires.
function onDeviceReady() {
alert("Device Ready");
document.addEventListener("showkeyboard", function(){ alert("Keyboard is ON");}, false);
document.addEventListener("hidekeyboard", function(){ alert("Keyboard is OFF");}, false);
}
I have tested this on Android 4.2 and 4.3 worked fine on both.
To turn fullscreen off:
Remove NoTitleBar
from your AndroidManifest.xml
:
android:theme="@android:style/Theme.Black.NoTitleBar
And / or add these lines to the onCreate
method in your MainActivity.java:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);