nbk
nbk

Reputation: 1992

How to use Phonegap SoftKeyboard Plugin for Android?

I am developing an Android application using Phonegap. I need to make the softkeyboard appear programatically. I am using the SoftKeyboard plugin which is found here. Can anyone tell me how to properly include this plugin & make it work? I have tried the tutorial found on the Phonegap Wiki, but the plugin is not working.

[Update] I have added the plugin to the path

com/zenexity/SoftKeyBoardPlugin/SoftKeyBoard.java

Updated plugins.xml and included

<plugin name="SoftKeyBoard" value="com.zenexity.SoftKeyBoardPlugin.SoftKeyBoard"/>

Then in the www folder added softkeyboard.js, and the following in index.html

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

But nothing happens, the keyboard is not displaying..

Upvotes: 22

Views: 13989

Answers (5)

Kousik
Kousik

Reputation: 22465

go through the link. here is the full project:--

SoftKeyboardPlugin by Simon McDonald

Upvotes: 0

Maj0rPaine
Maj0rPaine

Reputation: 176

Cordova 3.0 + JQM 1.3.2: Changing "fullscreen" to "false" in config.xml fixed the "adjustPan" and prevented my inputs from being covered when the keyboard displayed. However, blur() would not close the keyboard and this plugin worked wonderfully.

For the almost latest version of phonegap:

  • Add SoftKeyBoard.java to your app package in src
  • Add softkeyboard.js to assets/www
  • Update config.xml with: <feature name="SoftKeyBoard"><param name="android-package" value="com.yourAppPackage" /></feature>
  • Call your plugin: plugins.SoftKeyBoard.hide(function() {//success }, function() {//fail });

Upvotes: 0

originalgremlin
originalgremlin

Reputation: 121

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);

Upvotes: 9

darryn.ten
darryn.ten

Reputation: 6983

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

Upvotes: 11

James Harris
James Harris

Reputation: 41

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
});

Upvotes: 2

Related Questions