Send notification message to application

Posted on

Question :

I’m developing an APP and need to send warnings to users using this APP.
Example, in APPs of shopping sites, when a promotion appears a message arrives the Application about the promotion. The user reads and the message goes out.

How can I do this?

This APP is for a school, and my idea is that for example, the school’s management can write a message through a web page and that this message can reach the parents who use the APP on their cell phone telling them about meetings , bulletin deliveries, etc.

Any tips?


Answer :

Hello from google IO 2016 the message service was transferred to Firebase which made the initial deployment simpler, as it does not require the need for a server to send the messages.

Add to build.grad:

dependencies {
   compile ''

You can send messages through the firebase console that would be an initial solution. Then move on to another solution in php, java, or another language that dominates.

Add to your android manifest:


To handle incoming messages use the following class:


import android.content.Context;
import android.content.Intent;
import android.util.Log;


public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";

 * Called when message is received.
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
// [START receive_message]
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
// [END receive_message]

 * Create and show a simple notification containing the received FCM message.
 * @param messageBody FCM message body received.
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle("FCM Message")

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */,;

With this your application will already receive messages via console.
There is a lot to be done following the Firebase page that has a lot of documentation and where I got this information:

Firebase Cloud Message

I hope I have helped.


This service is called Push Notification (Cloud Messaging) , there is no way I can explain it with codes as it is a very extensive service.

In the documentation for Android, there is a very efficient explanation:

Here you’ll find examples of how to work with the feature:

In this way, the direction of the school through an online page, post the title and description of the ad, and will reach everyone who has the app installed.

Any questions put here that help you.



Leave a Reply

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