I have zero knowledge about firebase
. I have recently learned how to push data into the realtime database
:
I have created a
Firebase
project and included both my android app as well as website.After that I have included these
script src
into my html page:<script src="https://www.gstatic.com/firebasejs/9.10.0/firebase-app-compat.js"></script> <script src="https://www.gstatic.com/firebasejs/9.10.0/firebase-database-compat.js"></script>
In my javascript, I am initializing my firebase with all the config details fetched from my project settings:
const firebaseConfig = { apiKey: "AIzaSyBIJmvWbzdexxvyMGS-u5LFTOPlgWE6AO4", authDomain: "nfr-qtr-electric-billing.firebaseapp.com", projectId: "nfr-qtr-electric-billing", storageBucket: "nfr-qtr-electric-billing.appspot.com", messagingSenderId: "123052283905", databaseURL: "https://nfr-qtr-electric-billing-default-rtdb.firebaseio.com", appId: "1:123052283905:web:f0fc4ef2165122e112c800" }; firebase.initializeApp(firebaseConfig);
After that I am pushing some data into my
realtime database
which is in an array:for(var i=0; i<arr.length; i++){ firebase.database().ref("emp_details/0/").push({ "Name":arr[i][0], "Address":arr[i][1], "Gender":arr[i][2] }) }
Now what I want to do is, with each data being pushed into the database, a notification should be sent to the android phone. I have no idea, as to how to proceed. I have followed all the firebase
documentation pages, but they are way too complicated to understand.
In my android app, I have created a Firebase messaging
service class which should check for incoming notification messages and should show them:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
//How do I show the notification here?
}
}
Can anyone please help me out?