Aluf

Plugin-Phonegap android

Jan 25th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* pluginName.js */
  2. /* start plugin Scope. */
  3. (function(){
  4.     var cordovaRef = window.PhoneGap || window.cordova || window.Cordova;
  5.  
  6.     function GAPlugin() { }
  7.  
  8.     GAPlugin.prototype.init = function(success, fail, period) {
  9.         console.log("init....GAPlugin");
  10.         return cordovaRef.exec(function(ss){alert("Call back success.."+ss)}, fail, 'GAPlugin', 'initGA', [period]);
  11.     };
  12.  
  13.     if (cordovaRef && cordovaRef.addConstructor) {
  14.         cordovaRef.addConstructor(init);
  15.     }
  16.     else {
  17.         init();
  18.     }
  19.  
  20.     function init () {
  21.         if(!window.plugins) {
  22.             window.plugins = {};
  23.         }
  24.         if(!window.plugins.gaPlugin) {
  25.             window.plugins.gaPlugin = new GAPlugin();
  26.         }
  27.     }
  28.  
  29.     if (typeof module != 'undefined' && module.exports) {
  30.         module.exports = new GAPlugin();
  31.     }
  32. })(); /* End plugin Scope. */
  33.  
  34.  
  35. /* index.js */
  36. document.addEventListener("deviceready", init, false);
  37. var gaPlugin;
  38. function init(){
  39.         gaPlugin = window.plugins.gaPlugin;
  40.         gaPlugin.init(nativePluginResultHandler, nativePluginErrorHandler, "swagat...");
  41. }
  42. function nativePluginResultHandler (result) {
  43.     console.log('nativePluginResultHandler: '+result);
  44. }
  45. function nativePluginErrorHandler (error) {
  46.     console.log('nativePluginErrorHandler: '+error);
  47. }
  48. /* End index Scope. */
  49.  
  50.  
  51. /* Start GAPlugin.java Scope. */
  52.  
  53. /* import package_name */
  54. public class GAPlugin extends CordovaPlugin {
  55.         @Override
  56.         public boolean execute(String action, JSONArray args, CallbackContext callback) {
  57.  
  58.              if (action.equals("initGA")) {
  59.                 try {   Toast.makeText(this.cordova.getActivity().getApplicationContext(), "swagat", 3000).show();
  60.                         callback.success("initGA - id = " + args.getString(0));
  61.                         return true;
  62.                      } catch (final Exception e) {
  63.                         callback.error(e.getMessage());
  64.                      }
  65.         return false;
  66.         }
  67.      }
  68.  
  69. /* End GAPlugin.java Scope. */
  70.  
  71.  
  72. /* Start config.xml Scope. */
  73.  <plugins>
  74.         <plugin name="GAPlugin" value="package_name.GAPlugin"/>
  75.  </plugins>
  76. /* Endconfig.xml Scope. */
Advertisement
Add Comment
Please, Sign In to add comment