In this example implementing Google Cloud Messaging (GCM) for android. Using Google Cloud Messaging (GCM) sending push notification from web server to registered android devices. Using php as server side language and mysql as database.
Later i will provide example to send push notification from one device to other device.
Example WorkFlow :
STEPS : We will follow these steps
1. Register with Google Cloud Messaging from GOOGLE API Console and get Sender ID and API key for Google Cloud Messaging.
2. Set Emulator for Google Cloud Messaging helper library.
3. Create Android project to register with Google Cloud Messaging(GCM).
4. Create server side code to save Google Cloud Messaging registration id in our database and send push notification to device.
2. Set Emulator for Google Cloud Messaging helper library.
3. Create Android project to register with Google Cloud Messaging(GCM).
4. Create server side code to save Google Cloud Messaging registration id in our database and send push notification to device.
STEP 1 : Register with Google Cloud Messaging from GOOGLE API Console (Create a Google API project)
Follow the instrunction from http://developer.android.com/google/gcm/gs.html or follow below steps.
a. Open the Google APIs Console page.
b. If you haven't created an API project yet, this page will prompt you to do so:
a. Open the Google APIs Console page.
b. If you haven't created an API project yet, this page will prompt you to do so:
c. After creating project you can see the project id in the url. Note down the project id which will be further used as SENDER IDin android project. (Example: in #project:460866929976 after semicolon 460866778899 is the sender id)
https:
//code.google.com/apis/console/#project:460866778899
d. In the main Google APIs Console page, select Services.
e. Toggle on Google Cloud Messaging for Android.
e. Toggle on Google Cloud Messaging for Android.
f. Click on API Access and note down the API Key. API key will be used when send push notification requests from our server(php script) to GCM server.
/*********************************** STEP1 END ************************************/
STEP 2 : Set Emulator for Google Cloud Messaging helper library.
Before start writing android code we need to install the helper libraries and make required changes to the emulator. Helper library methods we will used to register / unregister with GCM.
a. Goto your android SDK folder and open SDK Manager and install Google Cloud Messaging for Android Library under Extras section. (If you don’t see Google Cloud Messaging for Android Library update your SDK manager to latest version)
a. Goto your android SDK folder and open SDK Manager and install Google Cloud Messaging for Android Library under Extras section. (If you don’t see Google Cloud Messaging for Android Library update your SDK manager to latest version)
沒有留言:
張貼留言