In recent times, Google moved from Google Cloud Messaging (GCM) to Firebase Cloud Messaging. Just like GCM, FCM is a cross-platform messaging solution that allows you to send messages.
![Xampp 64 Bit Terbaru 2016 Calendar Xampp 64 Bit Terbaru 2016 Calendar](/uploads/1/2/5/5/125509772/581192414.png)
Jan 02, 2019 Works with All Windows (64/32 bit) versions! Xampp Latest Version! Fully compatible with Windows 10; Disclaimer xampp is a product developed by Apache Friends. This site is not directly affiliated with Apache Friends. All trademarks, registered trademarks, product names and company names or logos mentioned herein are the property of their. Jul 02, 2013 XAMPP is the most popular PHP development environment XAMPP is a completely free, easy to install Apache distribution containing MariaDB, PHP, and Perl. The XAMPP open source package has been set up to be incredibly easy to install and to use.
FCM is completely free and there are no limitations. If you have followed any of my previous tutorials about, I strongly recommend you migrate to Firebase today itself.
![Windows Windows](http://distrowatch.org/images/slinks/grml-small.png)
In this article we learn the features of firebase cloud messaging by building a simple app. We’ll also learn how to integrate firebase to your backend, so that you can send the messages from your server. Sending Messages from PHP Backend Sending message from firebase console is not always an optimal solution for lot of apps. Huge number of apps requires an automatic notification to user whenever there is an event, which is not possible using firebase console.
To overcome this problem you need to integrate the firebase API from your backend server. Let’s create a simple PHP project to send the messages from backend.
I am assuming you are having basic knowledge of PHP and WAMP. If you are new you can get the help from this.
5.1 Obtaining your Firebase Server API Key Firebase provides Server API Key to identify your firebase app. To obtain your Server API Key, goto firebase console, select the project and goto settings, select Cloud Messaging tab and copy your Server key. Hi ravi i am new to android apps.
I was facing a problem that the following methods are deprecated PowerManager.FULLWAKELOCk method in wakeLock = pm.newWakeLock(PowerManager.FULLWAKELOCK SetButton method in alertDialog.setButton(“OK”, new DialogInterface.OnClickListener Notification notification = new Notification(icon, message, when); notification.setLatestEventInfo(context, title, message, intent); The highlighted methods are showing the methods are deprecated.i was unable to resolve these please help me out. It does seem like this is, indeed, leftover from a tutorial.
After some reading and testing, I’ve found that this is a key-value pair sent as an Extra in the Intent received by the onMessage(Context context, Intent, intent) method in the GCMIntentService class. Both the key in this array (currently, “product”) and the key in the onMessage method on your GCMIntentService class (currently, “price”) should be the same for it to actually show a message. Note that a similar array is defined in the sendmessage.php file, whose key should also be the same as the others. If they’re not all the same, you’ll be getting “null” as the message received by your app. Hi Ravi, This is great, thanks for all your work putting this together for all of us.
A lot of people are having problems with receiving messages after a successful registration. I also had them, and after checking WAMP’s log files, it seems it had not been properly configured to use the phpcurl extension. Even after turning it on (wamp-PHP-PHP Extensions-phpcurl), it still wasn’t working. I checked the log again, and my System, for some reason, couldn’t find the phpcurl.dll, even though it was clearly there in C:/wamp/bin/php/php5.3.13/ext. I did some digging, and apparently there’s a bug involving wamp, phpcurl and Windows 7 x64.
I did a two things, but I don’t know if they were both necessary: Install Apache 2.2.9 addon version from WAMP site. Download a “fixed” curl extension from. The Thread-Safe version worked for me (the other one didn’t) Also, enable curl in your php.ini file in your php folder. Hope this solves some people’s problems.
Hi, thank you! Everything work fine, but I have two question.
If I receive a message it will be shown in the statusbar. If I click on the message it opens the app and a message comes up with “Already registered with GCM”. But my received message is not there. If I stay in the app and receive a message, then the message is shown in the app. How can I solve this problem, that always a received message is shown in the app and not just when I have the app open?
The second thing is, how can I change the Textview into a Scrollview. If I change the Textview into a Scrollview I’ll get an error at this line (MainActivity!): lblMessage.append(newMessage + “n”); Thank you! When you press on the notification, it merely starts MainActivity based on the Intent passed as pendingIntent to the notification, in the method generateNotification. If you simply want it shown when you open the app through the notification, the following will work: In the method GCMIntentService.generateNotification, look for the line Intent notificationIntent = new Intent(context, MainActivity.class); and add this line right after it: notificationIntent.putExtra(“message”, message); Now go to your MainActivity.onCreate method. In it, look for messageTextView = (TextView) findViewById(R.id.textviewmessage); and add this line right after it: messageTextView.setText(i.getStringExtra(“message”); This way, you’re putting the message as an extra to the intent that starts your MainActivity when you press on your notification. Then, you’re retrieving this extra in your MainActivity class. This is probably not the best way to do it, but it should help you understand how it works.
As for the ScrollView, it is actually a FrameLayout, not really something that could replace a TextView. You should read up on ScrollViews in the android documentation. That’s because android works in another subnet. 1) Connect your phone to WIFI. 2) You have to execute cmd in your pc, then ipconfig, and search for the router address. IPv4: 192.168.1.101 or something like that. Then you have to replace in android SERVERURL, inside GCMIntentService, localhost by 192.168.1.101 3) If you are executing ECLIPSE PHP to run the index.php you have to modify the file php.ini inside C:wampbinapacheapache2.2.22bin.
You have to delete “;” in the line:;extension=phpcurl.dll. =D My english suck.
I hope this help you! Hi Ravi, This is great tutorial, thank you so much. I have one question about sending multicast message, I am not sure if its correct or no, but do I just loop through all the registered id’s and send the message or there is other efficient way to do this ??
I noticed in the comments several guys asking about why messages not received, in my case I did have the same issue while I am playing with code and it was because I changed the array id. So If you changed the array id (“Price”) on the php side, just make sure to match it with receiver side on the android app, otherwise you wont see the message sendmessage.php $message = array(“price” = $message); The reciever on the andorid app. String message = intent.getExtras.getString(“price”); Thank you again. Hi ravi, thanks a lot for your c2dm (old GCM) tutorial but now, as we know that c2dm is deprecated by google as we can see here can you make a tutorial about the new GCM as we can see here i’ve tried myself, using this source but in Android 2.2, it shows SERVICENOTAVAILABLE and i think C2DM can support any OS like 2.2 or higher, but new GCM just support high android version like 4.2 or higher but i dont know it for sure, thats why, im asking you maybe you or anybody who read this can share about this new GCM, thanks ?. I have few questions Ravi Sir. How to detect and remove / manipulate canonical ids.
How to detect which id is failing to reach GCM server. Why do ‘Null’ data(s) is sent automatically in Database always?
I need to delete it manually sometimes. Do device ‘registration id’ remain permanent or it changes with time? If so then how can it be resolved if Person A among 1000 user’s id changes and it’s hard to detect which device reg id changed.
I just like your tutorial very much, it’s really really facinating. First of all you make a very good work! Congratulations and thank you! To others, why does not work the registration? Just because you use a free hosting server, if you put all of the php scripts to a VPS or to any reliable hosting, it should be working! But I use WAMP on my WinXp and tested on a real Android phone with v2.3.7 and a Samsung Tab 2 with v4.0.4.
It is worked perfect all of my devices, I get all GCM messages. But I have a question: How to implement to store the user country on my server instead of “name”? I dont want to store email or name i just want to store the android phone user’s country name (i dont want to use geolocation) when it’s registered on my server. Is it possible? Hi Ravi, fantastic post!
I’m working on a project where the user of my application can get a notification when there are updates on the database server and then download for the updated database to the application. But I don’t know how to do that. Is this post the right answer for my question?
If it yes, I bit confuse about your post, why the user have to register to the server manually? Can we do it automatically? So everyone has the application installed on their phone will automatically registered to the server. I don’t know much about android, I’m very very new here. Maybe anyone here can help me, many thanks for any advice.
I think this Method is deprecated as Google api console now modified to Google cloud console. Android developer site also providing different implementation method for GCM which is not very clear for me. Can you please upload the changes we have to made in this code to make it work with new Google cloud console?
What changes we need to make in this code to make it work with new API console? As in previous version we add GCM jar in lib folder but with the new API console we need to add Google play dependency in the project. Please tell us the changes in this version.
We will be thankful to you. You may have the wrong API Key for your server. In the tutorial, the Google Developer Console shows an API Key for BROWSERS and NOT ‘API key for Android’.
Create a new key at APIs & Auth Credentials Create New Key. From there you can create a key for a server, browser, android or iOS. A lot of tutorials say to use a Key for browsers, but my notifications still wouldn’t send.
If that’s the case, then I suggest using a Key for Servers. If you’re still having problems I suggest making a new file ‘test.php’ or whatever, and using the content here: Once you fill out the proper variables and navigate to the page you can see if you’re getting a Unauthorized 401 error (in which case there’s still something wrong with your API key). Hello ravi, i saw ur posting it’s very helpful for me to be new in gcm. I am getting some error in my code for gcm based project.
I am creating one project on homesecurity so in that i have three button on,off,Home on(i.e. When the person comes to his house). When i press off button then the status of alarm should be register on the given url and so on for rest two off them. But when i click on the button the value is being posted on that specified url but after pressing any of the button my screen becomes blank. So, help me out of this problem.
On most devices this code has been working perfectly, but for some reason on one device I tested on it gave me a message: “From GCM: error(AUTHENTICATIONFAILED)” and it doesn’t register the device on the database. I looked up the problem in Google’s GCM class and it seems to have something to do with an incorrect password for a google account on the device, which doesn’t make any sense because on all my other devices I can type anything into the “Email” field when registering on the home screen and it still registers fine. Anyone else get this error?
Hi, Appreciated the tutorial, I have been prepared the setup and every thing went fine. Only one concern is that when I do register from the emulator, I didn’t see any message in the next activity as your device is registered. I have given serverurl, and tried both browser key and server key in server side php code, database tables also prepared but no data is populated when I do register in the emulator. But I’m not sure why I couldn’t see the message in the screen after the registration step. Can any one suggest me in this regard. I have connected two real android mobiles such as 4.2.2 and 2.3.3 to the development IDE.
From my PhP server, the push notifications are going well only to 4.2.2. But not for 2.3.3. Similarly two emulators of the same kind such as 4.2.2 and 2.3.3 are connected and tried to send notifications. But the emulators couldn’t received them. I’m not aware of why these all happening in a discriminatory way. I’m still try to figure out the technological edge of this problem, may be some expert like the author of the article in this field can give us better understanding. WELL DONE may god bless you for this great work works fine just for notice every one should replace the server url with its own server ip!!
Firstly you should get your machine ip from your cmd: go to your cmd - type “ipconfig” then copy the IPV4 adress for instance 192.xxx.x.x then you should know the wamp server port in order to connect to register.php page usually the wamp server port is 80 but in my case i changed to 8080 so the server url is going to be like this: “good luck ?. Hi Ravi, i followed the same steps in both android as well a php, its working fine!! I am getting Notification message also. But i face one major problem in displaying the message. When application is closed i receive the notification message but when i drag it, the contents will not be displayed.
I am getting a blank page. How to get that particular activity when click of notification message.If that view is opened and a new message is sent then it will be shown on that view. Kindly someone please let me know the solution. I am not getting notification in My Android Device.
I Changed config.php file(PHP) and CommonUtilities.java(Android) – config.php (Username,Password,Database & Google API Key) – CommonUtilities.java (Server URL,Sender ID) I am run application in android device and register with NAME & EMAIL. After getting message “From Demo Server: successfully added device!” After this message i m go to the database n check table – One row inserted in table with same name and email (It means php connection working very well). I am trying to send notification to registered user but not getting notification.
Please help me. I am trying this exaple.i found a problem.you are using PROPERTYONSERVEREXPIRATIONTIME = “onServerExpirationTime”; and PROPERTYONSERVERLIFESPAN = “onServerLifeSpan”; first time when i rigistered It was not inseted into database but updataed into shared prefs.
When i am trying to register again you are already registered message is coming. The insrt call back nad saving in shared prefs are not synchronized i hink. No wi could not know when the time expires, and there is no option to unregistered even if i want to use this in a real project the unregistered code is very important! How much time I need to wait for next trial? How could i unrigister the user after the temporaray service broken for the user?
Hi Ravi, Thank you very much for this tutorial:) I have one query about server url like What should be the server url? It got working only when I go the system settings-network - pick the ip address and paste it in server url. But I wants to know what if other user registers with this network address? I am connecting to internet via wifi hotspot of my real device.
So registration is successful on this perticular device. And as soon as I try to register from my other device (having its own internet) registration fails:( I don’t understand whether I am giving wrong server url. Please help me to resolve this doubt.