As soon as the data enters the realtime database, I want to send a notification (with some data from the firebase, like title, description etc. that is posted to firebase realtime database) to the users nearby to the location(within the radius of 3 km) from where the data is posted to the firebase.
Till now I know how to get the data from nearby locations but I don't know how to send a notification (when the app is closed) as soon as new data enters the database from the user's nearby location..
If anyone know how to do that, please tell.
I have read documentations and saw demo apps but I can't figure out how to do that..
Here is how I am getting data posted in nearby locations of the user and displaying it in recycler view-
db = FirebaseDatabase.getInstance().getReference("REPORTED-CUBS")
geofire = GeoFire(db!!.child("REPORTED-CUBS-LOCATION"))
val r_cubs_al = ArrayList<DataModel>()
geoQuery = geofire!!.queryAtLocation(GeoLocation(latitude, longitude), 3.0)
try {
geoQuery!!.addGeoQueryEventListener(object : GeoQueryEventListener {
override fun onKeyEntered(key: String, location: GeoLocation) {
try {
db!!.child(key)
.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
val r_cubs: DataModel? =
snapshot.getValue(DataModel::class.java)
if (r_cubs != null) {
rv_police.visibility = View.VISIBLE
tvNoCUBSReported.visibility = View.GONE
r_cubs_al.add(r_cubs)
rv_police.adapter = ReportedCUBSAdapter(r_cubs_al)
}else{
rv_police.visibility = View.GONE
tvNoCUBSReported.visibility = View.VISIBLE
}
}
override fun onCancelled(firebaseError: DatabaseError) {
println("The read failed: " + firebaseError.message)
}
})
}catch (e : Exception){
e.printStackTrace()
}
}