Push notification is the process of delivering information from the back end application to end user’s mobile device without any request from the end user. We can send the push notifications from Laravel application using AWS SNS service easily.
AWS SNS (Simple Notification Service) is a flexible, fully managed push notification service provided by Amazon web services. Using this, we can send messages to individuals or large numbers of recipients. Amazon SNS makes it simple and cost effective to send push notifications to mobile device users, email recipients or even send messages to other distributed services.
In this blog, we will see about sending push notifications to android devices with FCM (Firebase Cloud Messaging).
FCM is a cross-platform messaging solution that allows us to send messages for both Android and Apple devices.
Step 1 :
Firstly, we need to create an project in Firebase and get the Legacy server key for Cloud messaging.
Step 2 :
Then create an application in AWS SNS with GCM platform.
It will create an ARN for your application.
Then add the this ARN in your .env file
Step 3 :
In laravel, We need to use the following package,
This makes the developers to access Amazon Web Services in Laravel code.
And Add your AWS credentials in aws.php config file.
Step 4 :
Then we need to get the device tokens with the corresponding platform (Android) from User App.
Here, we have got the device token and generated the end point ARN for our Mobile using the Android application arn and stored in the database.
Step 5 :
Finally, we can send Push notifications using the already generated end point ARN.
We can also pass the the custom data through push notifications.
It is more efficient if you send notifications using queues.
More about queues, refer this link
So in this post we have seen in detail about how to send a push notification to Android Devices using laravel, FCM and SNS. In future posts we will see some other feature that can be integrated with Laravel and AWS so work in perfect manner.