I have 2 apps a customer booking app and an admin receiver app. they are both connected to the same Firebase database. When a customer makes a booking I can view this in my admin app. But how can I make it so that I receive a notification in the admin app once a booking is made in the customer app?
I have found this code but how could I implement it so that it shows the notification even if the admin app not open?
Uri notificationSoundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(subject)
.setContentText(object.getString("body"))
.setAutoCancel(true)
.setSound(notificationSoundURI)
.setContentIntent(resultIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, mNotificationBuilder.build());
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, ToneGenerator.MAX_VOLUME);
toneG.startTone(ToneGenerator.TONE_CDMA_HIGH_L, 3000);
((Vibrator)getSystemService(VIBRATOR_SERVICE)).vibrate(2000);
Edit
My Firebase tree looks like this
{
"Bookings",
"UserID Appears here",
"User booking info appears here"}
}
The bookings node is a constant and is always there, the user id appears once a booking is made. Could I have some sort of service that runs even when app closed that listens for the "UserID" node to update? then fire the notification method above? I've never worked with notification and services.