How to use Phonegap SoftKeyboard Plugin for Android? How to use Phonegap SoftKeyboard Plugin for Android? android android

How to use Phonegap SoftKeyboard Plugin for Android?


This is how I got SoftKeyBoard working in my application.

DroidGap Side

  • create /src/com/phonegap/plugins/SoftKeyboard with provided file SoftKeyBoard.java inside
  • add to /res/xml/plugins.xml:

    < plugin name="SoftKeyBoard" value="com.phonegap.plugins.SoftKeyboard.SoftKeyBoard" />

/assets/www Side

  • add provided file softkeyboard.js to /assets/www/js
  • add to index.html in the head where your other javascripts are included after you have included the phonegap javascript:

    < script type="text/javascript" charset="utf-8" src="js/softkeyboard.js"></script>

You can then call the following if you are on device or using something like Ripple:

window.plugins.SoftKeyBoard.show(function () {  // success},function () {  // fail});

or something like this if you want to make sure the namespace is available, which will prevent undefined problems:

((((window || {}).plugins || {}).SoftKeyBoard || {}).show || function(){})();

I think maybe where you went wrong was not including the js/softkeyboard.js in your head of index.html.

Hope this helps you


For the latest version of PhoneGap (Apache Cordova 2.1.0) I had to do the following:

Installed these plugin sources which reflected the project name change:https://github.com/originalgremlin/phonegap-plugins/tree/master/Android/SoftKeyboard

  • Copy softkeyboard.js to your javascript library directory.
  • Copy SoftKeyBoard.java to src/org/apache/cordova/plugins/SoftKeyBoard.java

Put this in your HTML file, after including the cordova.js file:

<script src="/path/to/javascripts/softkeyboard.js"></script>

Add this to the bottom of the res/xml/config.xml plugins section:

<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />

Now, assuming this HTML:

<button id="keyboard">Toggle Keyboard</button>

This jQuery should do something useful:

var softkeyboard = window.cordova.plugins.SoftKeyBoard;$('#keyboard').toggle(softkeyboard.show, softkeyboard.hide);


Try it like this:

SoftKeyBoard.show(function () {    // success},function () {   // fail});

The code in the JS file does not put it in the "plugins" namespace.

Orjust use the PhoneGap plugins full namespace:

window.plugins.SoftKeyBoard.show(function () {    // success},function () {   // fail});