I just need to send a push notification to a specific users inside my Button OnClickListener
. Is it possible with userId
and all information of this specific user?
this is my Button
OnClickListener()
code
richiedi_invito.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
databaseReference = FirebaseDatabase.getInstance().getReference();
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
lista_richieste = (ArrayList) dataSnapshot.child("classi").child(nome).child("lista_richieste").getValue();
verifica_richieste = (String) dataSnapshot.child("classi").child(nome).child("richieste").getValue();
if (!lista_richieste.contains(userID)){
ArrayList lista_invito = new ArrayList();
lista_invito.add(userID);
if (verifica_richieste.equals("null")){
databaseReference.child("classi").child(nome).child("richieste").setValue("not_null");
databaseReference.child("classi").child(nome).child("lista_richieste").setValue(lista_invito);
}
else{
lista_richieste.add(userID);
databaseReference.child("classi").child(nome).child("lista_richieste").setValue(lista_richieste);
}
//invitation code here
Fragment frag_crea_unisciti = new CreaUniscitiFrag();
FragmentManager fragmentManager= getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, frag_crea_unisciti);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Toast.makeText(getActivity(), "Richiesta di entrare inviata correttamente", Toast.LENGTH_SHORT).show();
}else{
Snackbar.make(layout,"Hai già richiesto di entrare in questa classe",Snackbar.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
To send a push notification to a specific single user with Firebase, you only need is FCM registration token which is the unique identifier of the user device to receive the notification.
Here is Firebase FCM documentation to get this token : FCM Token registration
Basically :
Only the user id itself isn't enough to send a notification for a specific user.