Git Product home page Git Product logo

gcm-cordova's Introduction

Cordova GCM Push Notifications Plugin for Android


About

This plugin is for use with Cordova and in an Android project to enable push notifications via Google's GCM (Google Cloud Messaging) service. Previously, push notifications on Android used C2DM, but that has since been deprecated.

Important - this demo will not go through the complete registration process on an emulator (it will work on a real device). To get it to work on an emulator, you need to install the right libraries. You can follow this guide under the section titled "Installing helper libraries and setting up the Emulator"

Installation

Add the com.google.android.gcm and com.plugin.GCM packages to your project. Add the GCMIntentService.java file to your application's main package.

Modify your src.app_name.gcm.GCMIntentService.java "package" name on the first line to use you application name.

Modify your AndroidManifest.xml to include the following lines to your manifest tag, replacing your_app_package with your app's package path:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="your_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="your_app_package.permission.C2D_MESSAGE" />

Modify your AndroidManifest.xml to include the following lines to your application tag, replacing your_app_package with your app's package path:

<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
  <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    <category android:name="your_app_package" />
  </intent-filter>
</receiver>

<service android:name=".GCMIntentService" />

Modify your res/xml/config.xml to include the following line in order to tell Cordova to include this plugin and where it can be found:

<plugin name="GCMPlugin" value="com.plugin.GCM.GCMPlugin" />

Follow the instructions here 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). 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.

Support

Get Support

Notes and Gotchas

If you run this demo using the emulator you will not receive notifications from GCM. You need to run it on an actual device to receive messages or install the proper libraries on your emulator (You can follow this guide under the section titled "Installing helper libraries and setting up the Emulator")

If everything seems right and you are not receiving a registration id response back from Google, try uninstalling and reinstalling your app. That has worked for some devs out there.

Google gcm supports booth json and plain text messages but this plugin is setup for json use only

If you copy the AndroidManifest.xml settings from the readme page on github, you may run into issues with invalid whitespace. If so, remove all white spaces and manually re-add them or copy the manifest settings directly from the file (not the web).

LICENSE

The MIT License

Copyright (c) 2013 Mark Nutter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gcm-cordova's People

Contributors

awysocki avatar bionicmaster avatar elanper avatar grnadav avatar krtek avatar malko avatar marknutter avatar roshammar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gcm-cordova's Issues

onMessage scenario error

I'm currently adding Notification logic to the app' using your plugin: GCM-Cordova.
I'm running a test project with your plugin to study it, so I installed it on eclipse, and i'm running it on an android device.
I manage to register the device for GCM messages + receive messages successfully.

When The device receives a message from Google Cloud, it calls the onMessage event handler (line 55, in this file: https://github.com/marknutter/GCM-Cordova/blob/master/src/com/cordova2/gcm/GCMIntentService.java) .
The event handler reaches line 77 to run this command: GCMPlugin.sendJavascript( json ); This commands supposed to call whatever legal Javascript i inject into it on the webView.

However at that particular scenario, the onMessage scenario, the static class' GCMPlugin members are not initialized at all, so the GCMPlugin.sendJavascript( json ) fails since all members of GCMPlugin are null.

As a result the message can't be delivered to the webView.

Summing it up: there is a need to handle an incoming message in a way that when the user taps a Notification - that tap not only turns on the application (or moves it back to the front if was paused), but also enables an ability to transfer some values from the Notification data to the UI using a javascript call.

App force closes when push is recieved on phonegap 2.2.0

I just installed the plugin and everything works fine, the registration process goes smoothly and i get an id.
But when a push message is sent to the app, it force closes with the error message "the application has stopped unexpectedly please try again".
Please how can this be fixed.
Am testing on a real device
Phonegap: 2.2.0

Installation instructions unclear

1 "Add the com.google.android.gcm and com.plugin.GCM packages to your project." -
cordova plugins add com.google.android.gcm
cordova plugins add com.plugin.GCM
both return error - how am I supposed to add these packages?

2 "Add the GCMIntentService.java file to your application's main package."
Where do I get the GCMIntentService.java that author means -
GCM-ordova/src/com/cordova2/gcm/GCMIntentService.java in the plugins source?
In what folder is "application's main package" under my Cordova project?

I am not too experienced with cordova yet, sorry if stupid questions...

Subscribe to GCM Topic Messaging ?

I'm able to receive GCM Downstream Messages through this plugin. I would like to register the app instance to receive GCM Topic Messages. How can get the Instance ID of the app ?
Kindly guide to do this.

Download your example but can`t resolve: CallbackContext, CordovaPlugin

The example here use cordova 2.1 and it seem this version of cordova can`t resolve and import CallbackContext nor CordovaPlugin.

Is that the problem?

PLease, i have a project using cordova 2.1 and i need to use this plugin with this version of córdova. Is this possible? Is there any version of this plugin for cordova 2.1.

Please it is important for me, sorry, my English is very bad.

Thaks in advance.
Best regards

No sound, vibration nor badge customization (do you have Android?)

Dear Mark, the phonegap staff that develops the PushPlugin have pointed to you as the responsible for the Android implementation.

Now, let's compare your Android with the iOS implementation:

// Android
pushNotification.register(successHandler, errorHandler, {
"senderID": "***",
"ecb": "onNotificationGCM"
});

// iOS
pushNotification.register(tokenHandler, errorHandler, {
"badge": "true",
"sound": "true",
"alert": "true",
"ecb": "onNotificationAPN"
});

Did you notice something missing? :-)

Is there any possibility of having your plugin completed, with the missing "alert", "badge" and "sound" attributes for Android? I mean, the 86% of the market share as of december 2014. That would be very much appreciated. Also provide your PayPal for donations please, thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.