Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send notification from the server to user segment who installed the app

In Firebase console, I saw the option to send a notification to User Segement with app "com.example" (where com.example is the app name).

As the image shows:

enter image description here

But how to do it from the server side using the FCM REST API:

https://fcm.googleapis.com/fcm/send

like image 291
Santhosh Avatar asked Dec 26 '16 10:12

Santhosh


People also ask

What is push notification medium?

Push notifications are messages that pop up on a users device. A user can see these notifications without having to be on the app. This is important for users retention. WHAT WE ARE BUILDING.

How do I send push notifications to OneSignal?

Configuring OneSignalYou need to configure OneSignal for each of the mobile platforms it will be working on. Once your configuration is done, you'll have an Application ID and a REST API KEY from OneSignal. You can configure OneSignal for iOS and Android.

How do I send app notifications from server?

Create a google API project. Enable push notifications for the project and get a API key. Get a registration ID through android app (each device has a registration ID for a specific application) Create a server application to send your push messages as push notifications through google servers by GSM.

What is notification payload?

Let's have a look at a notification payload: Whenever there is a title and body in your notification, the system will handle it for you in the background. When there's data in your payload and you click the notification, you're able to handle it in your service.


2 Answers

Unfortunately, it is not possible to send messages to User Segments using the FCM REST API.

As an alternative, you'll have to make use of the other ways to send messages to multiple devices, like simply using the registration_ids parameter and Topics Messaging (which I think is the most preferable for your use-case).

Here are samples on how to send this using Postman or cURL.

like image 85
AL. Avatar answered Sep 23 '22 18:09

AL.


i found a solution u can subscribe your app to a specific topic for example your app package name in your FirebaseInstanceIdService class so u can send data massage like

 {
  "to" : "/topics/your_package_name",
  "data" : {
    "key1" : "value 1",
    "key2": "value 2",
   ...
  }
}

here is the code to subscribe your app to topic in FirebaseInstanceIdService class

     public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService
    {
        private final String TAG="your_tag";
        @Override
        public void onTokenRefresh() {


        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        FirebaseMessaging.getInstance().subscribeToTopic("your_app_package_name");
        }
}

its worked for me

like image 31
ehsan khormali Avatar answered Sep 22 '22 18:09

ehsan khormali