Image push notification with Google cloud messaging - php

How to attach the image in push notification with Google Cloud Messaging ..Is it is possible to attach image, can any one tell how to attach..(or) it is possible like attach image in the form of URL/Text.. please provide me some sample example..

Maximum size of the push message can be upto 4KB. Therefore it is recommended to put the image on server somewhere and pass the url link of that image via push.

I don't think that's the correct approach. Each GCM message is limited to 4KB of data, so unless you want to send messages as it was somekind of TCP protocol, you shouldn't use it.
Sending images is probably better to be done with a HTTP POST request to the remote server (as the GCM architecture requires), and afterwards process it.

Related

sending fcm notification messages to multiple android devices by registration_ids parameter

I want to send notifications to multiple android devices(where same app is installed) by fcm from php server side by calling this url -
https://fcm.googleapis.com/fcm/send
I checked sending messages to device groups but my requirement is such that there will not be definite devices to which i will send messages because i am going to do it in a hourly cron job, and each time a cron job runs it will send notification messages to different different devices according to requirements. or can it be done in another way?
But i am thinking to use "registration_ids" parameter instead of "to" parameter, details of these fields here in the Downstream HTTP messages section. In this registration_ids field i will put all required device registration tokens in array. Now my question is after receiving message in android device can the message be parsed in the android app sdk codes?. i am in a bit of doubt as in this documentation there are no mentions of registration_ids parameter when sending messages to multiple android devices. Please assure me. And furthermore, will the message be sent when android app is in background?!. Please don't write one line, provide some examples if possible.
In the documentation for building requests to send to multiple devices you will find an example of passing multiple FCM tokens in a single call to the FCM API in the tokens parameter (in Node.js) or by using a HTTP batch request with multiple subrequests (in the REST API).
If you're having a hard time making this work, posting a question that shows what you tried increases the chances that someone can help making it work.
Yes, the message is sent regardless of whether the app is in the foreground, or in background. Whether the notification is actually shown depends on many more factors, many of which are outside of your control (such as the Android version, device maker/OEM, and the user settings).

Chorme Web Push Notification with payload

self.addEventListener('push', function(event) {
var jsonObj = event.data.json();
}
I have written chrome web push notification, but event.data is always null.
Currently I am using GCMPushMessage library, I think I need php curl for sending notification. Can anybody help me to send web push notification with payload?
As of 2015 , this related SO post stated, this is an intended behavior.
A downside to the current implementation of the Push API in Chrome is that you can't send any data with a push message. Nope, nothing. The reason for this is that in a future implementation, payload data will have to be encrypted on your server before it's sent to a push messaging endpoint. This way the endpoint, whatever push provider it is, will not be able to easily view the content of the push message. This also protects against other vulnerabilities like poor validation of HTTPS certificates and man-in-the-middle attacks between your server and the push provider. However, this encryption isn't supported yet, so in the meantime you'll need to perform a fetch to get information needed to populate a notification.
As provided by the document you have to fetch the information then populate it in the notification.
An update was released March 2016 named : Web Push Payload Encryption
Prior to Chrome 50, push messages could not contain any payload data. When the 'push' event fired in your service worker, all you knew was that the server was trying to tell you something, but not what it might be. You then had to make a follow up request to the server and obtain the details of the notification to show, which might fail in poor network conditions.
Now in Chrome 50 (and in the current version of Firefox on desktop) you can send some arbitrary data along with the push so that the client can avoid making the extra request. However, with great power comes great responsibility, so all payload data must be encrypted.
Ensure you've followed the implementation needed for applying payload in web push for Chrome. Like some Client-side changes and Server-side changes.
Hope this helps.

How to set which page app opens on tap of GCM push notification

I'm writing an API service in PHP that needs to send push notifications through GCM to client devices. I have everything set up and have an idea of how to do this but not sure of a few things.
1.Suppose the app has to open the page of a particular post when a notification is tapped, is there anything I have to set on the server while sending the notification? Like a link, etc?
2.Also, I'll be setting collapse keys in the notifications. Is it possible for the app the retrieve these collapse keys when notifications are opened so that the app can make an api call to let the service know the notifications have been read?
I do not have any knowledge of android but I would like to know what possibilities are there.
Answer to First Point : You need to just catch the extra bundle value(s) (ex. a post_id referring to particular post) from gcm to android and pass that value to the activity that you want to open and there you can make a call to a PHP file or web service requesting data to that particular post_id.
Answer to Second Point : yes you can get the values of collapse keys in android to handled in IntentService.
I am just telling you the way to get it :
Bundle extras = intent.getExtras();
String collapse_key = extras.getString("collapse_key");
after that you can normally use switch case to handle intents for different collapse keys.

MMS Service or Email service for application

I need some help figuring out how to develop the following proposed solution:
Users should be able to send a photo via MMS message to a number - this image then needs to be picked up and processed through a web application. The application is currently written in PHP and works with manual file upload, how could I incorporate the MMS functionality into this so that it could process the users image. The application takes an image and modifies it. This is the final image that would need to be returned to the user (again via MMS)
Secondly, there also needs to be functionality for a user to email an image to an address (eg email#example.com) - the application then takes the image, processes it through the application and emails it back to the user.
Any advice or direction would be much appreicated.
For the SMS aspect of your requirements, you should check out Twilio, they are for sending and receiving SMS, thought I'm not sure how they function with MMS. Still worth looking over though.

How to update a mysql database via SMS text messaging?

I want to add an additional functionality to a CMS I am making that will allow users to add content to a site via text message. The user should be able to upload an image and add text and send the message to a number which when received will update the database accordingly.
Can this be done, and can it be done via PHP because that's the only language I know? Also what would be the general outline to achieve such a thing?
You have to find a SMS gateway that supports "incoming" of SMS. Click-a-tell is generally the one people choose because of their API and documentation, they aren't free though. If you do a quick Google search for "SMS Gateway" you'll find plenty of other solutions.
Once you choose the gateway you want to go with, the rest of the process is easy. You would just handle the SMS as a regular request into your application.
Hope that helps you get started!
Use one of the many SMS gateways out there like Twilio (whom I work for, but loved before I was an employee) which has a really simple API and great documentation. There are tons of PHP examples. When you receive a message, a simple POST request is made to a URL you specify with parameters for To, From and Body. Also if you return text from the URLs you use to receive messages you can respond back to them. You can also initiate outbound SMS from the same number using the REST API.
Twilio does not currently support MMS (needed for your image uploading requirement) and is not free, but you only pay for what you use at $.01 per message.
Completing the answer by Raphael Caixeta, I recommend that you use the standalone PHP binary to run a pre-determined script, which parameters you'll get from the SMS/MMS. This way you can separate the two process:
1) Make a script and test it by running it through the command line.
2) Implement the SMS/MMS receiver software so that it parses the messages and runs the first script with custom parameters.
You can use a GSM/3G modem (or dongle) to receive SMS messages. And this sms software can read those messages from the modem in real time and put them automatically in your database.

Categories