Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* pluginName.js */
- /* start plugin Scope. */
- (function(){
- var cordovaRef = window.PhoneGap || window.cordova || window.Cordova;
- function GAPlugin() { }
- GAPlugin.prototype.init = function(success, fail, period) {
- console.log("init....GAPlugin");
- return cordovaRef.exec(function(ss){alert("Call back success.."+ss)}, fail, 'GAPlugin', 'initGA', [period]);
- };
- if (cordovaRef && cordovaRef.addConstructor) {
- cordovaRef.addConstructor(init);
- }
- else {
- init();
- }
- function init () {
- if(!window.plugins) {
- window.plugins = {};
- }
- if(!window.plugins.gaPlugin) {
- window.plugins.gaPlugin = new GAPlugin();
- }
- }
- if (typeof module != 'undefined' && module.exports) {
- module.exports = new GAPlugin();
- }
- })(); /* End plugin Scope. */
- /* index.js */
- document.addEventListener("deviceready", init, false);
- var gaPlugin;
- function init(){
- gaPlugin = window.plugins.gaPlugin;
- gaPlugin.init(nativePluginResultHandler, nativePluginErrorHandler, "swagat...");
- }
- function nativePluginResultHandler (result) {
- console.log('nativePluginResultHandler: '+result);
- }
- function nativePluginErrorHandler (error) {
- console.log('nativePluginErrorHandler: '+error);
- }
- /* End index Scope. */
- /* Start GAPlugin.java Scope. */
- /* import package_name */
- public class GAPlugin extends CordovaPlugin {
- @Override
- public boolean execute(String action, JSONArray args, CallbackContext callback) {
- if (action.equals("initGA")) {
- try { Toast.makeText(this.cordova.getActivity().getApplicationContext(), "swagat", 3000).show();
- callback.success("initGA - id = " + args.getString(0));
- return true;
- } catch (final Exception e) {
- callback.error(e.getMessage());
- }
- return false;
- }
- }
- /* End GAPlugin.java Scope. */
- /* Start config.xml Scope. */
- <plugins>
- <plugin name="GAPlugin" value="package_name.GAPlugin"/>
- </plugins>
- /* Endconfig.xml Scope. */
Advertisement
Add Comment
Please, Sign In to add comment