0

Now i have succeeded to send FCM Push Notifications one to one

the problem is:

i can't do it from one to multible users <==

Like if one member in a group chat send an message so i need to send a notification for every member in this group by the message content.

my current code:

private void sendNotification(String receiver, final String username, String senderImage, final String message) {
    noteListener1 = refToken.document(receiver).addSnapshotListener(new EventListener<DocumentSnapshot>() {
        @Override
        public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
            if (e != null) {
                Log.d(" MyFirebaseMessag", "error" + e);
                return;
            }
            if (documentSnapshot != null && documentSnapshot.exists()) {
                Token token = documentSnapshot.toObject(Token.class);
                Data data = new Data(currentUserEmail, R.mipmap.ic_launcher, username, ": " + message, "New Message",
                        OtherUsersEmail, senderImage, chatType, chatRoomId,membersCanWrite);
                assert token != null;
                Sender sender = new Sender(data, token.getToken());
                apiService.sendNotification(sender)
                        .enqueue(new Callback<MyResponse>() {
                            @Override
                            public void onResponse(@NonNull Call<MyResponse> call, @NonNull Response<MyResponse> response) {
                                if (response.code() == 200) {
                                    assert response.body() != null;
                                    if (response.body().success != 1) {
                                        Toast.makeText(MessagesActivity.this, "Failed!", Toast.LENGTH_SHORT).show();
                                    }
                                } else {
                                    Log.d(" MyFirebaseMessag", "response.code() != 200");
                                }
                            }
                            @Override
                            public void onFailure(@NonNull Call<MyResponse> call, @NonNull Throwable t) {
                            }
                        });
            } else {
                Log.d(" MyFirebaseMessag", "documentSnapshot null");
            }
        }
    });
}
Ayman.dev
  • 51
  • 12
  • I have explained in one of my tutorials step by step, how you can send **[notifications](https://www.youtube.com/watch?v=6RzB4HXzQyA&t=3s&list=PLn2n4GESV0AmXOWOam729bC47v0d0Ohee&index=17)** to specific users using `Cloud Firestore` and `Node.js`. You can also take a look at my answer from this **[post](https://stackoverflow.com/questions/48298993/push-notifications-on-content-change/48299840)**. – Alex Mamo Dec 16 '19 at 09:17
  • my problem is in java,so i don't understand node.js – Ayman.dev Dec 16 '19 at 20:20

0 Answers0