Tuesday, 3 May 2016

Android Push Notification Server Code In Python



I was create Push Notification server code in python. Its successfully working My android app receives push notification from python code.


Requirements :

                                   1. python2.7

                                   2. pip2.7  install python-gcm

                                   3. Create New Project From Google Developer Console https://console.developers.google.com/




                                   4. Project Number == Sender ID (Android App Use this code)
https://console.cloud.google.com/home/dashboard

Select Your Project  Project Number is SenderID

                                   5. Android Server Key (This Api key used for our python)

Create Credentials ServerKey





                                   6. Once Android Project is Ready Device Id Stored in Google and Google gives Registration Id (Reg id is Used  for Our Python)



Python Code :

from gcm import *

gcm = GCM("AIzaSyAU94l_PxyhJaiKsocFHWtS3mKcI5eUg")#ServerKey from google

data = {'message': 'Hiiii Android', 'param2': 'value2'}

reg_id = "APA91bHrQ1bfhrceoZ4X_kKVOJxlPGdUDjZyUl8zC_6rIeRCQiE9XT3fpJobWb-AIOHKlR4-C6iAMTwGgddbJlxMcVqESZnKIeVFl756dfg8HI1ju5cburZ43icTK_biGiLadmkY79OfklLPaXDfqylXF5HvZ5WFKcpb7oQ"

gcm.plaintext_request(registration_id=reg_id, data=data)




Message is key : Hiii Android is value
this message sends to android phone.

Above Server side Code is success fully working I got Push.













  Android App Receives Push :