How to Send Push Notifications on Android Application

The number of users of mobile is very high, so if you want to increase your sales more then you have to add this feature to your Magento store. So For the Magento 2 eCommerce stores, Push notifications are the best feature with the Android Application.

This functionality in any Magento 2 store helps to re-engage the Android app users & keep them well informed about the latest offers, upcoming/ongoing sale & their orders.

Product Alert API: Get Magento 2 Product Alert Using API

If you have created an Android app for the Magento website, then this feature helps your customer to stay connected with you. Since in today's date mobile devices like smartphones or tablets are available with almost all types of customers. Hence mobile applications have become the most effective way for your Magento eCommerce website to reach your customers.

Email Notifications, Text Messages All this you want to show as push notifications which is the best way to reach out to the users. Magento eCommerce owners used to integrate their own Android app with the Magento store so then they can use this kind of functionality.

How to Override Block, Controller, and Model in Magento 2

Magento 2 Push Notifications Module

 

Magento 2 Push Notifications Types

Store owners in Magento e-commerce can also create and send custom push notifications by adding any type of text, graphics, and landing-page links to the notifications.

Let us go through these notifications about what kind of messages we can send and what kind of messages connect our customers more.

For this kind of facility, we can create a custom extension that provides facility to custom messages in the admin panel easily

1. Order Successful Notification

Whenever a customer places an order for a product on your eCommerce website, the message that he should see after its success is the product order successful message.
So in this way, a notification is sent saying that the order has been placed.

With a customized Magento 2 template for push notifications, it becomes way seamless to send notifications for sales, promotions, festivals, etc. The push notifications for Magento 2 mobile apps can be automated as well as sent manually.

2. Order Status Push Notifications

Whenever a customer places an order for a product, it is the responsibility of the store owners to keep them informed about its current status from time to time.

 

3. Abandoned Cart Push Notifications

If a customer comes to your website and he adds the product to the cart but does not complete it, then a message is sent to his mobile that you left your shopping cart without placing an order. With this, you can increase your sales more.

 

4. Custom Notifications

In this, you can send any kind of personalized message and you can also emphasize link graphics, etc.

 

Push Notifications on Android App Using PHP File

The below code will help you to send the static message on the android application. This is one of the simplest steps to implement the push notification by using PHP code, so if you are implementing the Magento 2 rest API then you can implement using these steps.

<?php
/**
* Developer: Hemant Singh Magento 2x Developer
* Category: Push Notification Magento 2 API
*/
$ch = curl_init("https://fcm.googleapis.com/fcm/send");

//The device token.
$token = 'cbZl0SJIQUOr4WanPfzzjq:APA91bExXY2xnnmk-TRJN52GeAR9_PHMsYrMbQwM159C2fh0tQa-S6ggNg3fBMDc72BGmzipE1k68I005HrvL1MSHpaHeBeE8lCLh49jEiw1qhZ1D3ZmFkdPZVI7wpag5qXByByVLFtG';

//Title of the Notification.
$title = 'Hello';

//Body of the Notification.
$body = 'Hello Body';

//Creating the notification array.
$notification = array('title' => $title, 'body'=>$body, 'sound'=>'default');

//This array contains, the token and the notification. The 'to' attribute stores the token.


$arrayToSend = array(
'to' => $token,
'notification' => $notification,
'data' => $notification,
'priority'=>'high' 
);

//Generating JSON encoded string form the above array.
$json = json_encode($arrayToSend);
//Setup headers:
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key= AAAABfcWdgc:APA91bGZcOSwGbuZrVIFdiFUMyjvnGvXYB31MeYmzdw3ZdE4dT6LTgsb85cm_n3Nth0kbWI7mNmNNWkb0uLyx3KPMfjW-tgEmnQzQDumeH2kL9ew-_yyluxvq4Kfv8DNmlK9pXKVTkLQ'; // key here

//Setup curl, add headers and post parameters.
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//Send the request
$response = curl_exec($ch);
//Close request
curl_close($ch);
//Print Success and Faliure Message 
echo "<pre>"; print_r(json_decode($response));

?>

 

Details at GitHub

 

Conclusion:

By using this Magento 2 Wishusucess push notifications extension you will be able to send the custom message text as a push notification to customer device token and effectively you can notify your customers directly through their mobile app.

If you want to implement these features in your mobile application then you can contact us.

 

Leave a Reply