I'm trying to write the server side of my android app that uses C2DM. I'm going to write it in php. I basically am just doing tests right now. I copied the chrome to phone example for the actual android app and modified it to my liking. Right now my biggest question is the registration.
Let me get everything straightened out.
When registering the device for the first time, the app talks directly to my server. The server grabs the deviceid and responds back with a 200. Right?
So, on the php side of things, I grab the device id like $deviceid = $_POST['deviceId'] Right?
add it to my database. then respond back to the app.. How exactly do I send a particular response back? I assume in the header? I'm unsure how to do that.
Please confirm or deny that I'm on the right track and clear up any confusion.
Thanks for the help.
You don't respond back to the app. You must register your server with google's servers to get a server authentication token. You then use that server token and the device token in a post request to google's C2DM service to have google's servers send a push notification to the phone. Your app and your server never directly communicate when a push notification is sent in C2DM, it is all done through google, yet you need to implement a mechanism for your server to know the device id of the device it wants to send a message to.
This is a pretty detailed guide, though the server code is in Java:
www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
Make sure you have really gotten the IDs before sending to the server. If you are using an emulator for testing, you could do an echo over at the php script so the message will appear in your logcat.
Google refreshes expired registration IDs so your application should be able to pick up new notifications/ids from google and handle the message by sending to the database.
Related
I am using Firebase Cloud Messaging for my android development with PHP as server side language. Right now, i'm able to :
Receive push notification sending using Firebase Console either both real apps and emulator.
Got it working when testing it out from terminal(curl)
So then, i tried sending from apps server(using php curl) instead of Firebase Console. And right now, encountered this weird message InvalidTokenFormat, Error 400 every time i'm request the POST request. Any thought?
Here is the link for Firebase Api were made : FirebaseApi Class
Feel free to ask for any inputs from meif above use case didn't clear enough. Thanks.
My mistake. The url should be(without slash at the end) :
https://fcm.googleapis.com/fcm/send
you need to send request to the firebase from your server with message of the notification and the token of the users then firebase will accept the request and broadcast the message to all the users (tokens that we provide) in form of a notification .
Firebase and device works on poll model, hence only firebase can send notification on your device , you can setup your poll with the device but google does not allow that because if each and every app starts to make a poll tunnel with the device , it will take up whole lot of resources.
Can you Post the raw request curl sends to the server? Normally curl does provide a printout for that, not sure about the php version.
CURLOPT_POSTFIELDS does not want a JSON. if you want to send a application/x-www-form-urlencoded request, use http_build_query($message) , or if you want to send a multipart/form-data request, give it the $message array directly.
I am using Openfire for the xmpp server and so far its been great. The problem I am facing now is with push notifications. The app is written in Xcode which gets user data from a PHP Api. Openfire is the xmpp server. The issue is that when the app sends a message to openfire I would need to also query the Php api to see if the user is online and if they are not, send a push notification. This would have to happen for each message sent and as you might guess that will affect performance with all those requests happening.
I have everything working, I just cant get past this hump. If only openfire would fife off a request of my choice upon receiving a message.
Can anyone suggest a better idea? Basically need to know if the user is online (presence) before so that I know to fire off the push notification.
One thing also for sending push notification php script is right or openfire have some plugin.
Thanks.
I think using php script to check for offline user is an expensive affair.
I have used ejabberd server. For which you can create custom modules using "offline_message_hook" and using this module you can invoke php script to send push notification.
This hook is called when someone send message to an offline user. Following link might be helpful.
http://jasonrowe.com/2011/12/30/ejabberd-offline-messages/
If you are stuck somewhere, I can help.
I am a php developer. I have a DB table(mysql) where username and their online status(either 1 or 0) is storing. Now I have to send the list of online users to ios, so that every moment ios can get updated record.
If ios sends request to server after every second then obviously, the data, which will be visible in ios side, would be updated.
But, I don't want this option.
If any changes occur in server side, then only ios can put a request to server and server will give response to ios. This is my plan. For that I thought APNS would be better. But when I came to know, its also not much efficient specially for showing online chat users, I think there should be another methodology or mechanism so that instead of using APNS, I can fix my issue.
Please suggest me which one would be better. Thanks in advance.
You may need web socket communication. Give PHPWebSocket a try.
You have options like phpWebSocke In which your client have to ping or send socket request to server. the same approach as you are describing in your question.
All though APNS is not 100% guaranteed that your client device get your message.
I highly suggest you to go for open source jabber server and client api(XMPP). OpenFire and 'Smack' & 'smackx' API will handle every thing behalf of you. and its open source. so no need to worry about license and no need to re-invent the wheel.
here is the links.
http://www.igniterealtime.org/index.jsp
http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/
https://groups.google.com/forum/?fromgroups#!topic/xmppframework/ctp5uTUau3M
I am trying to implement Push Notification using GCM,
Besically i am trying to send Notification to the GCM using my PHP server which will deliver it to my android application.
I have used code at androidhive!
The device is getting registered successfully but i am not receiving any notification at my device nor anything is visible at Google console.
I am not receiving any response from the link used https://android.googleapis.com/gcm/send or https://android.googleapis.com
Is there anything wrong in this approach?
Can anyone suggest me any authentic source for this?
Realizing that some people are facing issues implementing GCM. I have decided to post solution.
The example on AndroidHive is working perfectly. Its just the matter of correct configuration.
Replace project ID in Android app. (You can get project ID from you google's console link i.e google.com/apis/console/#project:xxxxxxxxxxxx:access)
Replace Server API Key on PHP Server(config.php)
Key for server apps (with IP locking).
You can get your IP from WhatIsMyIP.
Key for browser apps (with referers) will not work.
I am writing an IOS app that is basically a jabber chat app. I am using Openfire for the xmpp server and so far its been great. The problem I am facing now is with push notifications. The app is written in Xcode which gets user data from a PHP Api. Openfire is the xmpp server. The issue is that when the app sends a message to openfire I would need to also query the Php api to see if the user is online and if they are not, send a push notification. This would have to happen for each message sent and as you might guess that will affect performance with all those requests happening.
I have everything working, I just cant get past this hump. If only openfire would fife off a request of my choice upon receiving a message.
Can anyone suggest a better idea? Basically need to know if the user is online (presence) before so that I know to fire off the push notification and I dont want to fire off two requests from my app per message sent. Thanks.
In openfire the messages to offline users are stored in ofoffline table. So your php code neednot worry about the status of the user if der is any entry in the ofOfline table it means the user was offline. Now create a scheduler that will keep looking in the ofOfline table for offline messages club them together and push notification to the user
i have spen lots of time for in XAMPPHP Library but cant find any proper solution. so for develop a web base chat application with jabber server. rather than using XAMPPHP, you can use "http://strophe.im/strophejs/" it will be much faster than XAMPPHP and you can find more js plugin for Strophe js. and you can also find more ready made xmpp client base on strophe js. so it will better than XAMPHP.