I'm building a simple BLE scanner to scan for particular beacon. Currently, I was able to scan the beacon to get the Major, Minor and Rssi value in the logcat continuously until I hit the stop button. However, I'm still having problem on storing data into my internal storage for the entire rssi value that I have scanned earlier. When I checked my txt file in device file explorer, it only able to capture one rssi value for only one time instead of overall scanning. The code that I used to write the data into internal storage as below. Thank you
writeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
writeFile();
}
});
}
public void writeFile() {
String textToSave = inputField.getText().toString();
try {
FileOutputStream fileOutputStream = openFileOutput("Tutorial File.txt", MODE_PRIVATE);
fileOutputStream.write(textToSave.getBytes());
fileOutputStream.close();
Toast.makeText(getApplicationContext(), "Text Saved", Toast.LENGTH_SHORT).show();
inputField.setText("");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Check the definition of the openFileOutput
function. Somewhere inside there it should call a constructor like this: new FileOutputStream(File file, boolean append)
.
Make sure the second append parameter is set to true so that new records are appended to the file instead of overwriting the contents.