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");
}
}
});
}