Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to README/comments for easier plugin integration #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ Modify your res/xml/config.xml to include the following line in order to tell Co
<plugin name="GCMPlugin" value="com.plugin.GCM.GCMPlugin" />


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.

<script type="text/javascript" charset="utf-8" src="GCMPlugin.js"></script>


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 ##

Expand Down
34 changes: 17 additions & 17 deletions assets/www/CORDOVA_GCM_script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gApp = new Array();
gApp = [];

gApp.deviceready = false;
gApp.gcmregid = '';
Expand All @@ -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

}
Expand All @@ -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 );

Expand All @@ -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 )
{
Expand All @@ -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('<li>MESSAGE -> MSG: ' + e.message + '</li>');

Expand Down