top button
Flag Notify

How to Integrate GCM with QueryHome Community edition[Client Side Change]

+2 votes
141 views

Set up a GCM Client App on Android

A Google Cloud Messaging (GCM) Android client is a client app that runs on an Android device.

Pre-Requirement

Here are the requirements for running a GCM Android client:

  • GCM requires devices running Android 2.2 or higher that also have the Google Play Store application installed, or an emulator running Android 2.2 with Google APIs.
  • On Android devices, GCM uses an existing connection for Google services. For pre-3.0 devices, this requires users to set up their Google accounts on their mobile devices.
  • Google Android Key
  • Google Project ID

Preparation

Steps involved in GCM Client side application on Android

 

1. Get Started and pick a platform

Visit the link with your Google account https://developers.google.com/mobile/add

Pick Android App to enable service for Android Development.

 

2. Choose the App name

Write the Android Package name in the android app.

 

3. Select the Google services to add to your app.

Add your services that you want to provide and specifically select Cloud Messaging Service

Download the configuration file form the selected service. This file is to be placed inside your app source code

 

4. A sample code from QHGCM

Download the QH-Sample source code to proceed the coding with android app https://github.com/Atindrakn/QHGCM.git

This file is password protected rar file 

Password: queryhome123

 

5. Add the configuration file to your project

Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project.

 

6. Add SERVER_URL and SERVER_ID in your app

Now you need to add your server-url and project-id into your android studio project 

If you don't have your android app then follow the java file from sample code that will give you an idea where to put your server ID.

We have given a sample code where you will find a file name CommonUtilities,java

Search Server_URL and Server_ID initialize the server_url with the server link for sending the registration id to the webite server.

Paste your project Id as a initial value for server_id see the image bellow

 

An Android application needs to register with GCM connection servers before it can receive messages. When an app registers, it receives a registration token and sends it to the app server. The client app should store a boolean value indicating whether the registration token has been sent to the server.

 

7. Add the API Key to the admin panel of QueryHome

  • Go to Control Panel with administrator login.
  • Name the Key inside the Enterprise Secret Key field.
  • Add the API Key into the GCM API Key field.

 

8. Call JSON API

you can test the push notification by sending a http post request 

https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=
<Google Android Key>

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "
<registration id>"
}

The client side implementation is done, now you can integrate it to deploy your app.

A full GCM implementation requires both a client implementation and a server implementation. For more information about implementing the server side, see the 4th reference bellow.

posted May 23, 2016 by Atindra Kumar Nath

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button

...