My question is how to get time duration between shaking the mobile by using accelerometer in android. My default threshold value is 800, and speed calculation formula is:
speed = Math.abs(x+y+z - last_x - last_y - last_z)/ diffTime * 10000;
Here I want to get time duration between first shake and next shake. If the duration is more than 10 sec means alert have to generate.
I don’t know how to calculate time intervals in sensor concepts. Please help me.
Thanks.
Just use
System.currentTimeMillis()to get the time for the first shake and save it to some variable saypreTimeand when the user shakes again then you can get time difference simply subtracting like thisdiffTime = System.currentTimeMillis() - preTimeand now if the value of
diffeTime/(1000 *10) > 10then do your rest of calculation