Fabiola Reyes Fabiola Reyes - 19 days ago 10x
Android Question

How to send a notification on Android extracting data from the Firebase Database?

I know Firebase contains a section to send notifications, writing your message in console, but I want to get the values from a table to display the values in a notification. Is this possible?


This is how i did:

//Firebase Context Firebase.setAndroidContext(this); //URL database firebase Firebase ref = new Firebase(Config.FIREBASE_URL);

    ref.addValueEventListener(new ValueEventListener() {
        //DataSnapshot para leer datos de un bd
        public void onDataChange(DataSnapshot snapshot) {
            //Get Actual Value(getchildren)
            for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                //Getting the data from snapshot
                Person person = postSnapshot.getValue(Person.class);

                //Intent(Get components GUI)
                Intent intent = new Intent();

                //Allow External Application(PendingIntent)
                PendingIntent pInent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);

                Notification noti = new Notification.Builder(MainActivity.this)

                        .setContentText("Nombre: "+person.getName()+"\t\tDireccion: "+person.getAddress())

                //Cancel notification
                noti.flags = Notification.FLAG_AUTO_CANCEL;

                //Get Notification
               NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                nm.notify(1, noti);


        public void onCancelled(FirebaseError firebaseError) {
            System.out.println("The read failed: " + firebaseError.getMessage());