Welcome to the Android Push Notification using GCM tutorial. Introduction: Many app developers still struggle to implement Android Push Notification in their apps\/games.So what is actually a push notification.Push Notification are used by developers to inform user about new messages,events or any other thing which they can see without opening their app. In this tutorial i am going to tell you how to use GCM (Google Cloud Messaging) to send push notification on Android device.You can use this code in your android app,games made with LibGDX,Cocos2d-x with little modification.This tutorial contains PHP,MySQL & JAVA code. Step by Step sheet \tGetting project id & project number from Google developers site. \tApplication\u00a0Code \tServer side code (PHP,MySQL) \tSending push notifications Let's get started! Getting project id & project number from Google developers site. Go to this site https:\/\/developers.google.com\/mobile\/add?platformandroid (Make sure you are logged in your google account) \tFill app name - Push Testing \tFill package name - com.developerhouse.push \tClick on "continue to" button wait for few seconds it will take some time. click on enable Google cloud messaging Now the project has been created we have to go on this link https:\/\/console.developers.google.com\/ to edit IP address from which we can make request to send push messages & to get the API Key & Project ID Select project from drop down on top ,note down the Project ID & Project Number Now Click on Credentials sub menu button under API & auth you will see something like this,\u00a0note down\u00a0the API Key and click on it This is a optional step to make your push notification secure by adding the ip address of your server add ip address & click on save button Application\u00a0Code We have to write the code for android application which will send the device id first time so that it can be save on our server Create a application with the same package name which we have used while setting up GCM. Add google play services library in your project AndroidManifest.xml This class is used for\u00a0registering the Token in our web server .First it will get the token then it will save on our web server. RegistrationIntentService.java MyInstanceIDListenerService.java MyGcmListenerService.java Line 20 : MESSAGE_NOTIFICATION_ID is used to make notification same for example if you send another notification and user have not read the old one it will replace the old one Line 24 : Method which will receive the content from GCM Line 34 : Sound for notification Line 35 : Vibration Pattern Line 37 : Intent which will run on click of notification you can open link to browser or you can open the activity Constants.java GCM_SENDER_ID Project ID WEB_SERVER_URL URL to register user unique id MainActivity.java Server side code (PHP,MySQL) In Server side\u00a0we have to create a 4 PHP scripts for inserting the registration id & sending push notification.I am not going to explain basic steps to create PHP Script and MySQL DB for that you can check this link https:\/\/developerhouse.com\/blog\/2015\/08\/tutorial-1-connect-android-with-php-mysql\/ I am not focusing on design of the admin panel or anything related to it because our main focus will be on coding and getting your work done by adding Login Page(some of readers will be using it in their apps so it can be misuse) Also i am not saving the username and pass in MySQL DB there is no need for it at this moment it's just for learning purpose so that android developer can easily get push notification implemented without needing any PHP developer for php code. Create Database named push Table named registration These are the structure of these tables Name Type Length\/Values A I (Auto Increment) id INT Yes gcm_regid VARCHAR 300 No (By Default) created_at timestamp No (By Default) PHP Files connect.php \/\/ Change this for settings of MySQL DB login.php \/\/ To login into admin panel reg.php \/\/ For saving registration ID's send.php \/\/ For sending the push notification connect.php It's used for changing login page username,password & also for changing mysql details. login.php It's used for login into Android Push Notification panel so that no one can access it without username and password .You can change the username & password in connect.php file reg.php This is the file which will be requested through Android platform via HTTP Request. send.php This file is used for sending the push notification of our choice to the all users in group. Sending push notifications Now if you have followed the tutorial this step will work for you. So steps are \tOpen Android Costants.java file & replace\u00a0GCM_SENDER_ID variable value to the project number from project console ,WEB_SERVER_URL value to the one with your server url and file path for example if you have uploaded in wamp www then check IP of your computer it should be like this http:\/\/192.168.1.103\/reg.php or if you have used a Linux Hosting and uploaded in public_html your main domain is developerhouse.com then it will be https:\/\/developerhouse.com\/reg.php \tOpen connect.php change apiKey\u00a0value to the one we got from project console Api & auth -> Credentials \tCompile & Run the android application . Don't worry if it does not show anything because we have not made it for this purpose . \tIt will show Toast\u00a0Registered with web server if everything works well \tNow check PHPMyAdmin it will have a new value in registration table \tNow to send the Push Notification go to this url http:\/\/192.168.1.103\/login.php .Fill username & password.You will be redirected to the http:\/\/192.168.1.103\/send.php file it will show no. of registered user & a textarea with two buttons \tPress submit & check notification. \tFinish Code Download\u00a0Click here (Dropbox) Few Notes \tIn send.php i have used 1000 limit code because i had read this on few sites that in 1 request you cannot send push notification\u00a0to more then 1000 device id so i have created a loop for this (Of-course you can try other approach) \tI have not gave my focus to the design of Login page or Send page because you are admin you don't have to show this page to the world But a nice design is always best so feel free to change it\u00a0. \tI have edited the code from first version because it was not using\u00a0MyInstanceIDListenerService class it's useful if the token got expired or compromised it will refresh the token in onTokenRefresh which will call RegistrationIntentService .Another reason to edit the post was using PDO in PHP Files which can helps us to prevent SQL Injection.