I'm building two apps, one for booking a service and one for the managers to respond to the services requested by the clients, as soon as a booking is made it has to detect the location and according to that it has to send the order notification to the nearest manager. How do I do this. I'm using Google maps api to search the nearest manager and that piece of code is working fine. But I'm unable to integrate the push notifications as I have no idea about it. How do I use my server to do this and once the notifications is sent, if the manager doesn't respond, then I want the server to send the message again after 30 minutes. Please help me.. Thank you!
-
see https://stackoverflow.com/questions/55948318/how-to-send-a-firebase-message-to-topic-from-android/57449820#57449820 – Mahmoud Abu Alheja Aug 09 '20 at 14:44
2 Answers
I'm facing the same problem, so I will write my steps below.
FCM INSTALLATION
1) As google says Firebase Cloud Messaging (FCM) is the new version of GCM.
. So if you are starting with a new app, use Firebase Cloud Messaging instead.
You will need:
A device running Android 2.3 (Gingerbread) or newer, and Google Play services 9.4.0 or newer
The Google Play services SDK from the Android SDK Manager Android Studio 1.5 or higher
- An Android Studio project and its package name
2) Create a Firebase project or import existing one and follow the setup steps
FCM USE
1) To send a message to a specific device, you need to know that device's registration token. When you need to retrieve the current token, call FirebaseInstanceID.getToken()
. Also don't forget to implement onTokenRefreshcallback
. The onTokenRefreshcallback
fires whenever a new token is generated.
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
sendRegistrationToServer(refreshedToken);
}
2) After you've obtained the token, you can send it to your app server and try to send some messages.
- Install and run the app on the target device.
- Make sure the app is in the background on the device.
- Open the Notifications tab of the Firebase console and select New Message.
- Enter the message text.
- Select Single Device for the message target.
- In the field labeled FCM Registration Token, enter the registration token you obtained in a previous section of this guide.
That's in the short all you will find in documentation. Hope that it will help someone.

- 1,360
- 2
- 24
- 41
-
1Is there any approach for sending notification w/o having any server except firebase? – Devendra Singh Dec 04 '17 at 10:32
-
@DevendraSingh You can have a look on OneSignal. It is easier to implement and I think also prices are lower – kristyna Dec 04 '17 at 18:00
-
Thank you for such a detailed answer @kristyna I've implemented Firebase into my app. – user3908652 Jan 26 '18 at 20:36
To do this, you must get regId (gcmToken) from device which you want sent notification to. Then you can use a network lib (framework) in android to send a http request to gcm service. You can refer all in google cloud message guide of google. If you don't understand, You can comment below, I will help you.

- 1,180
- 3
- 16
- 36