Android Question Accelerometer write to file

apty

Active Member
Licensed User
Longtime User
I have used Erel's code for accelerometer http://www.b4x.com/android/forum/threads/orientation-and-accelerometer.6647/
to display x,y,z values. Now i want to add another value say t, that i can append to the x,y,z values and hence it will become x,y,z,t. The value t is the time of recording accelerometer values (datetime and nanoseconds). In java i can get the same t value this way
B4X:
long MiliTime = System.currentTimeMillis();

            long NanoTime = sensorEvent.timestamp;
          // Time now = new Time();
          // now.setToNow();
            Time t = new Time(Time.getCurrentTimezone());
            t.setToNow();
            String date = t.format("%Y/%m/%d %H:%M:%S");
            timevalue=String.valueOf(date)+NanoTime
I want to display the same in basic4android format. I also want to save this values (i.e. x,y,z,t) in a text file as comma delimited (e.g. -1.2233,0.9766,1.8990,20140514191005xvfcccc where xvfcccc is nanoseconds).
Please help me with sample code that can do the above.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
PhoneSensors doesn't expose the event timestamp field.

You can set DateTime.TimeFormat and DateFormat to match this format:
B4X:
DateTime.DateFormat = "yyyyMMdd"
DateTime.TimeFormat = "HHmmss0000000"
Dim n As Long = DateTime.Now
Dim time As String = DateTime.Date(n) & DateTime.time(n))
Dim str As String = x & "," & y & "," & z & "," & time
 
Upvote 0
Top