With this app two phones can send and receive Beacons every 1.1s.
I want to save the distance between those two phone into a txt file in order to analyse the information.
Let's assume the running time of the app is 60 s the txt file should have approx 54 rows and each row should have the updated distance between the phones.
I have already tried to implement this code :
val centralRangingObserver =
Observer<Collection<Beacon>> { beacons ->
beacons
.filter { x -> x.manufacturer == 0x0000 }
.forEach { beacon ->
Log.d(TAG, "$beacon about ${beacon.distance} meters away")
writeToFile("beacon.txt", beacon.distance.toString() + "\n")
}
}
private fun writeToFile(fileName: String, content: String) {
Log.d(TAG, "trying to write to file")
val path = applicationContext.getExternalFilesDir(null)
// val fileOutputStream = FileOutputStream(File(path, fileName))
File(path, "beacon.txt").appendText(content)
Log.d(TAG, "wrote to file")
}
The code however has two problems. It is complicated to find the txt file in the Files of the phone as the path is not predefined, Second, the value of the distance is overwritten so after 60s I only get one row/value not the 54 rows as expected.