Google Cloud Messaging test application - php

I'm a PHP developer and I have this assignment where I have to send GCM messages to an android application.
I have zero experience on developing android applications so I would like to know if there's a sandbox or a test application where I can test if my server is working properly.
I'm creating the server with these instructions:
GCM with PHP (Google Cloud Messaging)
It seems that I need a server api key (which I know how to create in the google developer console) but how can I create a blank application? I need exact tutorial since I know nothing about it.
I found this answer earlier: https://stackoverflow.com/a/12437549/1278155 but I have no idea what to do with the .zip file provided.

1
You need to register the App on Google Console. For this you need following information about the application to which you wish to send notifications:
SHA Certificate : This is a key that uniquely identifies the Machine on which the app is being created and the app itself. There is a Command Prompt command to get this key directly.
Package name : Each application has a unique Package Name as you have a URL for PHP projects.
The app developer can provide with these details. Then on successful app registration you will get ProjectCode and a Key. These will be needed in further process
2
Next to go a bit deeper and explain why all this information is required by GCM, you see on device side, the app needs to register the user with GCM and in return it gets a GCM-ID at run time. Then This GCM-ID received is passed on to the server side(You). The developer will need ProjectID and Key that was generated in #1.
3
Now when you trigger your code to fire a GCM, you mention the GCM-IDs to send the notification to specific devices or else you can mention the ProjectID that you receive at the time of app registration with Google Console. These parameters are handed over to Google's Side of things.
4
Now if you pass ProjectID, Google can fetch all corresponding GCM-IDs to this project-ID or else you have specifically passed some GCM-IDs. Then the Google will push a message to all devices corresponding to the GCM-IDs.
5
Still not over, The message reached the target device, but not the target Application on the device. So for this purpose we need the package name at the time of registeration o Google console.

Related

Show Message on Android App in Real time

I am developing an application, where a random number is being generated in an android app, and after that, I am inserting that code in Web Base app.
What I am looking for is, when I am updating the value from web app to MySql database, I want at the same time, to show a message on android app that number has been saved, without doing any action in Android app.
signage-e36e0: null
I have tried Firebase, but I don't think Firebase would be needed.
Any help would be appreciated.
You can show a message in the app once the Webcall for sending rendom number is finished from app side you can know that event in HTTP Client you are using.
If it's not possible for you to listen to HTTP Response then You can utilize Firebase Cloud messaging(FCM) for this.
When you change the value in the database you can send the message to the app via FCM and app will show a message on the screen based on that message.
https://firebase.google.com/docs/cloud-messaging/

Do I need to make 2 different applications for using GCM in android?

I tried searching these issues. Some sites say I need to do some stuff with php in order to make 3rd party server while others don't mention anything. some says it need JSON. Guide me please. PS I am a beginner and know java, XML,SQL only.
You should only need one server. The second server you are reading about may be the Google GCM cloud server? When I did a GCM project a few years ago, I had one server, it happened to be a App Engine instance. It generated events and sent them to Google via the GCM api and then onto onto the device. I don't remember it being that difficult.
I did have more than one server in the mix though, there were others that sent messages to the AppEngine server, but it was not required to send a GCM message.
Google Cloud Messaging (GCM) is a service that enables developers to send data from servers to both Android applications or Chrome apps and extensions.
So if you want to send data to the users of your App then you must have an interface or dashboard from where you can send some data (typically push notification) to the users of your app.
This dashboard (server from which you can send data) can be developed by using PHP or any script languages.
Now a though can come up in your mind:
"I am suppose to develop both the mobile app and the server then what
role does GCM play?"
Yes, GCM is playing a vital role indeed. The server we have to develop is just to design an interface so that you can type your message/notification and select the recipients. Rest of the part of (managing the queue, communication with the apps checking for authentication and all other stuffs will be done by mighty GCM )
In order to have an bird-eye overview you can take a look on this image collected form android hive
Server side coding is doesn't need you to be expert in php. So you can go through to this article. It helped me a lot to learn.

Windows azure push notication and catch the notification to a particular website page

Hi im working on a project who has an existing iOS app that uses windows cloud platform. Our task is to create a website for the app. One of the requirements is to enable to catch notifications created by the mobile app. For example if there is a new user, push notifications will be triggered and a website link will catch the notifications and save the data to a database. My question is, is it possible to catch a notification from windows azure push notification using a php script event listener?
I don't have any background on windows azure and i don't have any access to there windows azure account. The only thing they said is to give them the link of the script that will catch the notifications.
What are some steps thats need to be done?
Thank you
I'm not sure this is possible. Notification Hubs sets up communications so that you can send a notification out to a many different platforms at one time (Apple, Android, Windows Phone, Windows 8, etc.). Each device registers with the Notification Hub (or the registration is done for them by a back end) and provides a unique device ID, also known as a Channel URI. When you need to send a notification the Notification Hub then disperses that notification out to each of the correct Platform Notification Systems (PSNs) which then deliver the notification directly to the device.
I say all of that to indicate while it might be possible to register a listener that is not a device with the notification hub using a REST based API (You'd have to create a viable channel URI) I'm not sure there is any way to be listening as a php script to a PSN. Also, the registrations do expire from time to time and so you'd need to make sure to keep registering. Finally, no notification system is 100% guaranteed to deliver a notification. The device could be off, it could be in a bad reception area, bad network connection, or the PSN just doesn't delivery it for some reason, etc.
My suggestion is to take a step back and modify the code where the notification is being produced and send it both to Notification Hubs for device distribution, but also send the content of that notification to your database directly, or have them right the message to a queue which is processed in the backend to save to the database if the database isn't local to the code generating the notifications. This removes the notification hub involvement as far as your website is concerned.
If you really MUST look into the php script getting the messages then you can start by trying to figure out how php can receive messages from the PSNs, which is not an Azure issue. You can use the Notification Hubs REST APIs to register for them, but I'm very skeptical of that route.

whats the best way to implement real time push messages with apache, php and mysql only?

i'm trying to implement a chat application for android (where users can communicate people who are in same location). i'm thinking it of an facebook messenger with Geo specific oriented. i came across to terms like repeated pull, comet, bosh, websockects, socket programming, xmpp(which requires xmpp capable server like openfire) etc to do this. But my resources are fixed like apache, php (codeignter) and MySql only. I need to find the efficient to way to do this. Guys i need this. Please help me.
Thank you,
abbiya
The preferred approach on Android is Google Cloud Messaging.
Google Cloud Messaging for Android (GCM) is a service that allows you
to send data from your server to your users' Android-powered device.
This could be a lightweight message telling your app there is new data
to be fetched from the server (for instance, a movie uploaded by a
friend), or it could be a message containing up to 4kb of payload data
(so apps like instant messaging can consume the message directly).
The GCM service handles all aspects of queueing of messages and
delivery to the target Android application running on the target
device. GCM is completely free no matter how big your messaging needs
are, and there are no quotas.
Essentially, it works like this: Your server talks to Google, and Google pushes the message in real-time (or nearly so, as long as the device is powered on and connected to the Internet) to the Android device(s). There's a registration process that happens on the Android device the first time the app is installed (and at future points to revalidate the registration). In your Android app, it's your responsibility to send this registration ID to your server so you can store it for future use. Your server uses this registration ID when it wants to push a message to that device.
The communication protocol between your server and Google is JSON over HTTPS. Your server can use any languages/technologies, as long as it can communicate with Google's servers. A PHP/MySQL application can definitely meet the basic requirements for the service:
Before you can write client Android applications that use the GCM
feature, you must have an application server that meets the following
criteria:
Able to communicate with your client.
Able to fire off HTTPS requests to the GCM server.
Able to handle requests and resend then as needed, using exponential back-off.
Able to store the API key and client registration IDs.
On the client side, the Android device must be running API version 8 (Android 2.2) or later. Of course, it's also your Android app's responsibility to process incoming messages (using a BroadcastReceiver, as the Android system sends an Intent to your receiver whenever a message arrives), which allows you to handle messages however you want.

Push Notification using GCM - PHP

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.

Categories