From 55a7743b85d161207a058aa7d6c86ebf769f3434 Mon Sep 17 00:00:00 2001 From: Kimberly Hamper Date: Wed, 17 Jul 2013 15:38:41 -0400 Subject: [PATCH 1/3] Minor code clean-up and comment/README clarifications --- README.md | 7 +++++-- assets/www/CORDOVA_GCM_script.js | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 53d63b4..5c03f62 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Modify your res/xml/config.xml to include the following line in order to tell Co -Follow the instructions [here](http://developer.android.com/guide/google/gcm/gs.html) on creating a Google API project to obtain a GCM sender ID. Replace all instances of "your_sender_id" in this plugin with that id (make sure you pass the ID as a string, not an int). +Follow the instructions [here](http://developer.android.com/guide/google/gcm/gs.html) on creating a Google API project to obtain a GCM sender ID. Add your app to the [Google Play Store] and input your API keys in the "Services & APIs" section. No need to go live with the app to test it out. Add the GCMPlugin.js script to your assets/www folder (or javascripts folder, wherever you want really) and include it in your main index.html file. @@ -54,7 +54,10 @@ Add the GCMPlugin.js script to your assets/www folder (or javascripts folder, wh -In the CORDOVA_GCM_script.js script you will see an example of how to interact with the GCMplugin. Modify it to suit your needs. +In the CORDOVA_GCM_script.js script you will see an example of how to interact with the GCMplugin. Replace "your_sender_id" in the following line with your sender id number (make sure you pass the ID as a string, not an int), and then modify the script to suit your needs: + +window.plugins.GCM.register("your_sender_id", "GCM_Event", GCM_Success, GCM_Fail ); + ## Support ## diff --git a/assets/www/CORDOVA_GCM_script.js b/assets/www/CORDOVA_GCM_script.js index 9c03ee5..c9c521b 100644 --- a/assets/www/CORDOVA_GCM_script.js +++ b/assets/www/CORDOVA_GCM_script.js @@ -1,4 +1,4 @@ -gApp = new Array(); +gApp = []; gApp.deviceready = false; gApp.gcmregid = ''; @@ -23,17 +23,17 @@ document.addEventListener('deviceready', function() { gApp.DeviceReady = true; - // Some Unique stuff here, - // The first Parm is your Google email address that you were authorized to use GCM with - // the Event Processing rountine (2nd parm) we pass in the String name - // not a pointer to the routine, under the covers a JavaScript call is made so the name is used - // to generate the function name to call. I didn't know how to call a JavaScript routine from Java - // The last two parms are used by Cordova, they are the callback routines if the call is successful or fails + // Some unique stuff here: + // The first parameter is your Google senderID that you were authorized to use GCM with + // the Event Processing routine (the 2nd param). We pass in the String name, + // not a pointer to the routine. Under the covers, a JavaScript call is made so the name is used + // to generate the function name to call. I didn't know how to call a JavaScript routine from Java. + // The last two params are callback routines used by Cordova if the call is successful or fails. // - // CHANGE: your_app_id - // TO: what ever your GCM authorized senderId is + // CHANGE: your_sender_id + // TO: whatever your GCM authorized senderID is // - window.plugins.GCM.register("283007905632", "GCM_Event", GCM_Success, GCM_Fail ); + window.plugins.GCM.register("your_sender_id", "GCM_Event", GCM_Success, GCM_Fail ); }, false ); @@ -48,7 +48,7 @@ GCM_Event(e) switch( e.event ) { case 'registered': - // the definition of the e variable is json return defined in GCMReceiver.java + // The e variable contains JSON return defined in GCMReceiver.java // In my case on registered I have EVENT and REGID defined gApp.gcmregid = e.regid; if ( gApp.gcmregid.length > 0 ) @@ -68,7 +68,7 @@ GCM_Event(e) } - break + break; case 'message': // the definition of the e variable is json return defined in GCMIntentService.java From 737ba2148e5d56aca21a8b4bcfb6a00100272053 Mon Sep 17 00:00:00 2001 From: Kimberly Hamper Date: Wed, 17 Jul 2013 15:50:44 -0400 Subject: [PATCH 2/3] Minor code clean-up and comment/README clarifications --- README.md | 7 +++++-- assets/www/CORDOVA_GCM_script.js | 34 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 53d63b4..5c03f62 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Modify your res/xml/config.xml to include the following line in order to tell Co -Follow the instructions [here](http://developer.android.com/guide/google/gcm/gs.html) on creating a Google API project to obtain a GCM sender ID. Replace all instances of "your_sender_id" in this plugin with that id (make sure you pass the ID as a string, not an int). +Follow the instructions [here](http://developer.android.com/guide/google/gcm/gs.html) on creating a Google API project to obtain a GCM sender ID. Add your app to the [Google Play Store] and input your API keys in the "Services & APIs" section. No need to go live with the app to test it out. Add the GCMPlugin.js script to your assets/www folder (or javascripts folder, wherever you want really) and include it in your main index.html file. @@ -54,7 +54,10 @@ Add the GCMPlugin.js script to your assets/www folder (or javascripts folder, wh -In the CORDOVA_GCM_script.js script you will see an example of how to interact with the GCMplugin. Modify it to suit your needs. +In the CORDOVA_GCM_script.js script you will see an example of how to interact with the GCMplugin. Replace "your_sender_id" in the following line with your sender id number (make sure you pass the ID as a string, not an int), and then modify the script to suit your needs: + +window.plugins.GCM.register("your_sender_id", "GCM_Event", GCM_Success, GCM_Fail ); + ## Support ## diff --git a/assets/www/CORDOVA_GCM_script.js b/assets/www/CORDOVA_GCM_script.js index 9c03ee5..9dd7576 100644 --- a/assets/www/CORDOVA_GCM_script.js +++ b/assets/www/CORDOVA_GCM_script.js @@ -1,4 +1,4 @@ -gApp = new Array(); +gApp = []; gApp.deviceready = false; gApp.gcmregid = ''; @@ -7,7 +7,7 @@ window.onbeforeunload = function(e) { if ( gApp.gcmregid.length > 0 ) { - // The same routines are called for success/fail on the unregister. You can make them unique if you like + // The same routines are called for success/fail on unregister. You can make them unique if you like window.GCM.unregister( GCM_Success, GCM_Fail ); // close the GCM } @@ -23,17 +23,17 @@ document.addEventListener('deviceready', function() { gApp.DeviceReady = true; - // Some Unique stuff here, - // The first Parm is your Google email address that you were authorized to use GCM with - // the Event Processing rountine (2nd parm) we pass in the String name - // not a pointer to the routine, under the covers a JavaScript call is made so the name is used - // to generate the function name to call. I didn't know how to call a JavaScript routine from Java - // The last two parms are used by Cordova, they are the callback routines if the call is successful or fails + // Some unique stuff here: + // The first parameter is your Google senderID, which authorizes you to use GCM with + // the Event Processing routine (the 2nd param). We pass in the senderID as a string, + // not a pointer, to the routine. Under the covers, a JavaScript call is made so the name is used + // to generate the function name to call. I didn't know how to call a JavaScript routine from Java. + // The last two params are callback routines used by Cordova if the call succeeds or fails, respectively. // - // CHANGE: your_app_id - // TO: what ever your GCM authorized senderId is + // CHANGE: your_sender_id + // TO: whatever your GCM authorized senderID is // - window.plugins.GCM.register("283007905632", "GCM_Event", GCM_Success, GCM_Fail ); + window.plugins.GCM.register("your_sender_id", "GCM_Event", GCM_Success, GCM_Fail ); }, false ); @@ -48,8 +48,8 @@ GCM_Event(e) switch( e.event ) { case 'registered': - // the definition of the e variable is json return defined in GCMReceiver.java - // In my case on registered I have EVENT and REGID defined + // The e variable points to the JSON returned as defined in GCMIntentService.java + // In this case, I have EVENT and REGID defined on registered. gApp.gcmregid = e.regid; if ( gApp.gcmregid.length > 0 ) { @@ -68,14 +68,14 @@ GCM_Event(e) } - break + break; case 'message': - // the definition of the e variable is json return defined in GCMIntentService.java - // In my case on registered I have EVENT, MSG and MSGCNT defined + // The e variable points to the JSON returned as defined in GCMIntentService.java + // In this case, I have EVENT, MSG and MSGCNT defined on message. // You will NOT receive any messages unless you build a HOST server application to send - // Messages to you, This is just here to show you how it might work + // messages to you. This is just here to show you how it might work. $("#app-status-ul").append('
  • MESSAGE -> MSG: ' + e.message + '
  • '); From 9f63425a712f38b4d42f7e2fcce93745db95dfe7 Mon Sep 17 00:00:00 2001 From: Kimberly Hamper Date: Wed, 17 Jul 2013 16:06:05 -0400 Subject: [PATCH 3/3] Remove merge markers --- assets/www/CORDOVA_GCM_script.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/assets/www/CORDOVA_GCM_script.js b/assets/www/CORDOVA_GCM_script.js index b9346da..9dd7576 100644 --- a/assets/www/CORDOVA_GCM_script.js +++ b/assets/www/CORDOVA_GCM_script.js @@ -24,13 +24,11 @@ document.addEventListener('deviceready', function() { gApp.DeviceReady = true; // Some unique stuff here: -<<<<<<< HEAD // The first parameter is your Google senderID, which authorizes you to use GCM with // the Event Processing routine (the 2nd param). We pass in the senderID as a string, // not a pointer, to the routine. Under the covers, a JavaScript call is made so the name is used // to generate the function name to call. I didn't know how to call a JavaScript routine from Java. // The last two params are callback routines used by Cordova if the call succeeds or fails, respectively. -======= // // CHANGE: your_sender_id // TO: whatever your GCM authorized senderID is @@ -50,10 +48,8 @@ GCM_Event(e) switch( e.event ) { case 'registered': -<<<<<<< HEAD // The e variable points to the JSON returned as defined in GCMIntentService.java // In this case, I have EVENT and REGID defined on registered. -======= gApp.gcmregid = e.regid; if ( gApp.gcmregid.length > 0 ) {