Coder Social home page Coder Social logo

gcm-demo-app's Introduction

GCM Demo application

GCM is Google Cloud Messaging for Android.

This demo application is created with Ionic framework.

For GCM Push Messaging I have chosen AirBop service because it has a free plan.

The following image explains how GCM works (source: androidhive).

GCM architecture

Preparation

You need node.js and git preinstalled.

Install Ionic, Cordova and Bower:

npm install -g ionic cordova bower

Install Android environment (JDK, SDK) by following these instructions on Cordova docs.

Register at Google

Creating a Google API project

  • Open the Google Developers Console.
  • If you haven't created an API project yet, click Create Project.
  • Supply a project name and click Create.
  • Once the project has been created, a page appears that displays your project ID and project number.
  • Copy down your project number. You will use it later on as the GCM sender ID.

To enable the GCM service:

  • In the sidebar on the left, select APIs & auth.
  • In the displayed list of APIs, turn the Google Cloud Messaging for Android toggle to ON.

To obtain an API key:

  • In the sidebar on the left, select APIs & auth > Credentials.
  • Under Public API access, click Create new key.
  • In the Create a new key dialog, click Server key.
  • In the resulting configuration dialog, supply your server's IP address. For testing purposes, you can use 0.0.0.0/0.
  • Click Create.
  • In the refreshed page, copy the API key. You will need the API key later on to perform authentication in your app server.

Register at AirBop

Register at airbop.com with your email address.

Free Plan: Unlimited Push Notifications, 1,000 devices for free

Go to Dashboard, go to Add New App. Fill the form:

  • App Name ( gcmdemo )
  • Java Package Name ( gcmdemo.pbakondy.com )
  • Google API Key ( copy from the Google registration )

After a successful submit copy AIRBOP_APP_KEY and APP_SECRET values.

Create Ionic project

Run this command (you can replace appname and id but you have to use the same at AirBop registration)

ionic start --appname gcmdemo --id com.pbakondy.gcmdemo gcmdemo blank

cd gcmdemo

Add Push Notification handler Cordova plugin

ionic plugin add com.clone.phonegap.plugins.pushplugin

Add ngCordova and ionic-airbop-client JS libraries:

bower install ngCordova ionic-airbop-client

Copy/overwrite the files from this repository into your project:

  • www/index.html
  • www/js/app.js
  • www/js/gcm.js

Open gcm.js in editor and set the constant values.

Finally add Android platform and build the project.

ionic platform add android
ionic build android

You can build and run directly on your connected phone with this command:

ionic run android

Running the app

You will see a button with label "Register App". Tap on it. It will send a registration request to Google, and with the return "registration id" value it will register to AirBop server.

You should see your device on AirBop administration interface as a registered device. Now you can send push notification to your phone.

License

gcm-demo-app is licensed under the MIT Open Source license. For more information, see the LICENSE file in this repository.

gcm-demo-app's People

Contributors

pbakondy avatar

Watchers

 avatar

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.