Skip to content

Instantly share code, notes, and snippets.

@m00sey
Created June 17, 2011 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m00sey/1031746 to your computer and use it in GitHub Desktop.
Save m00sey/1031746 to your computer and use it in GitHub Desktop.
Code Snippets for PhoneGap Plugin Post
javac -d . -classpath <path_to_your>/android.jar:<path_to_your>phonegap.jar com/yourpackage/ToastPlugin.java
jar -cvf phonegap-toast.jar com/yourpackage/*.class
ToastPlugin.prototype.show_long = function(message, win, fail) {
PhoneGap.exec(win, fail, "ToastPlugin", "show_long", [message]);
};
<script type="text/javascript" charset="utf-8" src="phonegap-toast.js"></script>
window.plugins.ToastPlugin.show_long('Epic!');
var ToastPlugin = function() {
};
PhoneGap.addConstructor(function() {
// Register the javascript plugin with PhoneGap
PhoneGap.addPlugin('ToastPlugin', new ToastPlugin());
// Register the native class of plugin with PhoneGap
navigator.app.addService("ToastPlugin", "com.youpackage.ToastPlugin");
});
package com.yourpackage;
import org.json.JSONArray;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
public class ToastPlugin extends Plugin {
@Override
public PluginResult execute(String arg0, JSONArray arg1, String arg2) {
// TODO Auto-generated method stub
return null;
}
}
@leiyu0918
Copy link

hello, I download your source .but my application run errors(phonegap + android).
02-02 08:16:17.793: E/Web Console(526): TypeError: Result of expression 'window.plugins.ToastPlugin.show_long' [undefined] is not a function. at file:///android_asset/www/index.html:63
are you provide integrity application? thank you very much.

@kendrelaxman
Copy link

The code above does not work. gives the same error as above mentioned
what could be the possible reason??
error is :-window.plugins.ToastPlugin.show_long' [undefined] is not a function. at file:///android_asset/www/index.html:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment