Read now

How to make push notification using our custom API in android

Android push notification is a service which notifies you that has any new data come or not in your smart device.  

Android push notification is a service used by developers to send data to Android smartphones.

There are several different methods that can be used to implement Android push messages, the standard way is GCM (Google Cloud Messaging) but the alternatives are everywhere.

So here, We are using simply an alarmManager to make a request to the server after an interval and our custom API to make a response to android smartphones.

1. Make your pendingIntent and set alarm

This is your primary activity named, Here we have to set pendingIntent where pendingIntent is the instance of the Intent that starts the Activity when a user touches the push notification.

In above block of code,

alarmIntent – is an object of Intent.
PendingIntent – is the instance of the Intent that starts the Activity when a user touches the push notification.
AlarmManager – This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future.
PendingIntent.FLAG_UPDATE_CURRENT – Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent. For use with getActivity, getBroadcast, and getService.

Here we have set the interval of 1000 * 60 * 60 * 2. Means It will run after every 2 hr.

2. Make your BroadcastReceiver class

In step 2, We are making a BroadcastReceiver class named

Here, we send a request to the server and server send a response to the client (mobile device) and show to the form of push notification on smartphones.

In above code,

BroadcastReceiver – broadcast receiver who will intercept communication and notify us that something is working in our mobile. It is of 2 types:

NotificationCompat.Builder – Builder class for NotificationCompat objects. Allows easier control over all the flags, as well as help constructing the typical notification layouts.

3. Register your broadcast receiver class in AndroidManifest.xml

An application listens for specific broadcast intents by registering a broadcast receiver in AndroidManifest.xml file.

Paste this xml code inside your <application> tag.













. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again