Lorenzo Campana Lorenzo Campana - 3 years ago 171
Java Question

How can i send push notification to specific users just knowing the userID inside Button OnClickListener? Firebase

I just need to send a push notification to a specific users inside my Button

. Is it possible with
and all information of this specific user?

this is my

richiedi_invito.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {

databaseReference = FirebaseDatabase.getInstance().getReference();

databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
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();
if (verifica_richieste.equals("null")){



//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);

Toast.makeText(getActivity(), "Richiesta di entrare inviata correttamente", Toast.LENGTH_SHORT).show();

Snackbar.make(layout,"Hai giĆ  richiesto di entrare in questa classe",Snackbar.LENGTH_SHORT).show();


public void onCancelled(DatabaseError databaseError) {



Answer Source

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 :

  • You get a FCM token for the user
  • Then you store this FCM token on your server or database by associating this FCM token with the user ID for example.
  • When you need to send a notification, you can retrieve this FCM token stored on your server or database with the user id and use Firebase Cloud Functions. Here is a specific case study to send a notification for a specific user : Cloud Functions

Only the user id itself isn't enough to send a notification for a specific user.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download