I need to be able to store accelerometer data in a text file on Google Glass, plug the glass into a computer, and then be able to retrieve that written file.
I am not getting any errors/exceptions--the file just never appears.
Here's what I have so far (that doesn't work):
public void onCreate(Bundle savedInstanceState) {
...
try{
accFile = openFileOutput("acc_data.csv", MODE_APPEND | MODE_WORLD_READABLE);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Gathering the sensor data is definately not a problem since I can seex
, y
, and z
if I set a breakpoint.
public void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
String outString = "\""+currentDateTimeString+"\","+x+","+y+","+z+"\n";
if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
try {
OutputStreamWriter osw = new OutputStreamWriter(accFile);
osw.write(outString);
osw.flush();
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void onDestroy() {
...
if(accFile != null)
{
try {
accFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
And just in case, the android manifest has android.permission.WRITE_EXTERNAL_STORAGE