Home / Tutorials / How to add push notification in android application from android studio – Android developer (part – 2 Working with server)

How to add push notification in android application from android studio – Android developer (part – 2 Working with server)

If you followed my old post you have successfully added firebase notification method in your app.If you did’nt read it already follow this post

How to add push notification in android application from android studio – Android developer (part – 1 Connect with firebase )

Now its time for sending custom notification from own server. Why we need to use own server

=> For sending custom notification with data message

=> For opening specific activity on notification click

So let’s begin………….

Firstly,  you have to upload some php scripts for sending notification from the server [Code will be uploaded in the .zip file] or you can use our own server for testing purpose.. for that visit

http://androidrace.com/pushnotification/

then at the place of server key add your server key.. for getting the server key open firbase console=> select the app project=> select the settings icon from top left => project settings=> Cloud Messaging => Server key [You can also Legacy Server key but “Server Key”  is the upgraded version]

 

After that create a package named “app” in your app and create a class named Config in it

Now again create a package named “service” and add 2 classes named MyFirebaseInstanceIDService and MyFirebaseMessagingService

 

 

Now your app able to receive  notification from the server and open desired activity..

Now handle notification on your desired activity by using “get intent” method

For example create a new activity named Notification

Xml of this activity

Now you will able to see and handle notification sent by the server….

 

Now if you’re in the Notification activity.. and you get new notification at that time and you want to refresh the activity with new notification data override onNewIntent() in Notification activity

then your full code of Notification.java will be like

 

That’s all…. It will automatically handle new intent from the notification 😀

 

Now here is the source code of sample android push notification by using gcm project

Android push notification  simple source code

~ https://github.com/rana01645/android-push-notification

 

here is the source code of using own sever (Special thanks to Ravi Tamada)

Android push notification from own server

~https://github.com/rana01645/android-push-notification/tree/master/server

 

Enjoy  and if you like this post don’t forget to share with your friends…. happy coding 😀

 

About Rana

Rana
Love to do fun with programming and build something new.. :)

Check Also

android-push-notification-tutorial

How to add push notification in android application from android studio – Android developer (part – 1 Connect with firebase )

Assalamualaikum, Here is Rana to tech you how to add push notification in android app …

Leave a Reply

Your email address will not be published. Required fields are marked *