Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 188.8.131.52 release ready!
Owner and Founder. Opencart
Earlier the polling mechanish is used to get the notifications on your android application. But that method has disadvantages like load on network and reduced battery life.
Polling Mechanism: In this method the application contacts (or hits) server or cloud (whatever the case is) to get the new notifications. This increases the network usage and reduces the battery life. And also sometimes there is no new message so all the efforts go in vain.
Push Mechanism: In this approach the server/ cloud itself connect to the application device whenever there is a new notification available. So it had saved the resorces. But the process is extremely typical one have to deal with queues, saving the notifications for resending at the time of offline device. But to made all these things easy we can use GCM.
Google Cloud Messaging:
Google provides an easy way to implement push notifications called GCM. GCM sends data from your server to your users’ devices, and receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to client applications, and it is completely free.
GCM acts as a mediator between your server and client’s application. A full GCM implementation requires both a client implementation and a server implementation. I presume that you had already implemented the server implementation. The client implementation of GCM is extremely simple, you just have to fallow the below mentioned steps:
Step 1: Go to http://console.developers.google.com and register your project over there. On successful registration you will get
Step 2: Now add some support in your gradle files as:
Step 3: Add permissions as well as sevices and recievers to your app manifest file.
Step 4: For each user GCM generates a token (registration id). It is the unique id of the user through which the notification is sent to the clent. So each user have to register itself with GCM using your applications senderID. Add a boolean value to preference to determine that the to0ken is generated or not. If not then the app will generate a token n send it to your server. To do this extend IntentService class and register your app.
Your app or the Instance ID service may need to refresh tokens in the event of a security issue or when a user uninstalls and reinstalls your app during device restoration. Your app must implement a listener to respond to token refresh requests from the Instance ID service. This is implemented by YOUR InstanceIdService.
Step 5: Now just implement the listeners / recievers and you are ready to send or recieve your messages using GCM.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.