Skip to content

Dinesh2510/Android-Sending-Push-Notifications-From-Server

Repository files navigation

Android-Sending-Push-Notifications-From-Server

Follow the Steps:

Everything from generating tokens to receiving and displaying notifications

Notifications are important! I can’t recall using an app that didn’t have notifications excluding, of course, those apps that don’t serve a purpose like these. Notifications play a vital role in your app success. They give you a platform to reach out to your users, interact with them, give them updates, update the app data and much more. While notification is an important part of the whole app development process, it somehow is typical to integrate as compared to the normal android apis. The reason? Well, while normal apis need configuration inside the app only, notifications need more than that — outside configuration like handling user tokens, and sending notifications using those tokens.

String token = FirebaseInstanceId.getInstance().getToken();

Now we need to generate token using FirebaseInstanceIdService class and send it to the server to be stored. Create a new class InstanceIdService and extend it with FirebaseInstanceIdService. We now need to add a constructor and onTokenRefresh methods inside this class. We will take help of predefined tools in Android Studio. Click inside the class block and go to Code in the toolbar and select override methods. Select the desired methods and click ok. After the methods are added, we need to get the generated token everytime onTokenRefresh method is called by the framework