GithubHelp home page GithubHelp logo

anonprice / gcm-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brunogabriel/gcm-android

0.0 2.0 0.0 940 KB

This is a simple example how to use GCM in android Application to receive and send push (creating your own server request).

License: Apache License 2.0

Java 87.63% PHP 12.37%

gcm-android's Introduction

Android GCM - Google Cloud Message

This is a simple example of how to use GCM in Android applications. My motivation is help users to put this feature in your applications, because in some topics, I saw problems in how to implement it, but in general is very easy.

To create this repository, I read official GCM Page and Android API.

I will suppose that you have your bundle id application (in AndroidManifest.xml), in my example I will use:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.brunogabriel.nativegcm">

Register your account

First it is necessary to create and enable GCM by making a project, steps:

  1. With your package android in hands:

  2. Do not forgot to save your project number, we will use it in Android Application directly.

  3. Create your credentials:

    • When I made it, I did not saved an IP Address, only empty this field to test.
    • So now, write your credentials key.

Configuration: Android application

In Android project:

  1. First, please, read as soon as possible all comments (small quantity) in .java files, because some contains tips, e.g. in function executeBusinessRule, its possible for users save unique device id in databases (like chat application, to send notification or start a chat).

  2. In gradle file, has an important dependency: com.google.android.gms:play-services:8.4.0, to enable receive data.

  3. In string.xml, don't forgot to change gcm_default_sender_id value to your project number (step 2 in register account).

  4. Please, see implementation in AndroidManifest.xml, because there are features necessary to application work correctly.

  5. In MainActivity, we'll register your unique device id, first this application will validate if play services is enabled by calling isEnablePlayService, if there is no error, start 'RegistrationIntentService'.

  6. I advise all people to debug this app and collect first unique device id, to do, put a break point in RegistrationIntentService method onHandleIntent or executeBusinessRule to get this value, don't forget to write this in your notes to test server after. Do not forget, every time you install the application this id changes.

Some explanations

In GCMListenerService we've important features:

  1. onMessageReceived - Contains a bundle received, in our case, JSON Data (Bundle).
  2. sendNotification - Method that calls a device local notification, push alert.

Servers

Now, you need to encapsulate your message in a json request, in sequence, send to Google Server. Google has a responsibility to send data (push).

If you have no idea how to implement a server, see this section.

  1. PHP

Screenshots

Screenshot

References and Credits

LICENSE

Click here to see

gcm-android's People

Contributors

brunogabriel avatar

Watchers

 avatar  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.