How do I use the Android Accelerometer?

Start with this: public class yourActivity extends Activity implements SensorEventListener{ private SensorManager sensorManager; double ax,ay,az; // these are the acceleration in x,y and z axis @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); } @Override public void onAccuracyChanged(Sensor arg0, int arg1) { } @Override public void onSensorChanged(SensorEvent event) { if … Read more

Android TYPE_LINEAR_ACCELERATION sensor – what does it show?

Very interesting question!!!! I’m developing somethig similar to your application. What i found about TYPE_LINEAR_ACCELERATION isn’t happy for me. 1) TYPE_LINEAR_ACCELERATION, TYPE_GRAVITY, ecc are implemented only for Android 2.3 (and up) So i have Android 2.2 and i can’t test them. 2) TYPE_LINEAR_ACCELERATION isn’t so accurate as it would be, because there are some simple … Read more

how to calculate exact foot step count using accelerometer in android?

The first thing you need to do is decide on an algorithm. As far as I know there are roughly speaking three ways to detect steps using accelerometers that are described in the literature: Use the Pythagorean theorem to calculate the magnitude of the acceleration vector of each sample from the accelerometer. Low-pass filter the … Read more

How to get iPhones current orientation?

This is most likely what you want: UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; You can then use system macros like: if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) { } If you want the device orientation use: UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation]; This includes enumerations like UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown

How can i simulate accelerometer in android emulator? [closed]

The Android emulator doesn’t support it itself but OpenIntents’ SensorSimulator fills the void. Download and unpack the zip file, then start the standalone jar file: $ java -jar bin/sensorsimulator.jar Next, install SensorSimulatorSettings on the emulator using the adb tool which comes with the SDK: $ adb -s <emulator device> install bin/SensorSimulatorSettings.apk (run adb devices to find the … Read more

Detect change in orientation using javascript

NOTE: orientationChange is deprecated Instead use screen.orientation using the screenOrientation interface which is triggered by the screenorientation.onchange event window.addEventListener(“DOMContentLoaded”, () => { const output = document.getElementById(“o9n”); const displayOrientation = () => { const screenOrientation = screen.orientation.type; output.innerHTML = `The orientation of the screen is: ${screenOrientation}`; if (screenOrientation === “landscape-primary”) { console.log(“That looks good.”); } else … Read more

Gyroscope vs Accelerometer?

Actually, the accelerometer measures linear acceleration; but since force is equal to mass times acceleration, people can consider it as measuring force as well as long as it has a constant mass. Linear acceleration is the rate of change of linear velocity. A gyro on the other hand provides the angular rotational velocity measurement as … Read more

How is it possible that Google Fit app measures number of steps all the time without draining battery?

Thanks for asking this question! Battery is one of our top most concerns and we work hard to optimize Google Fit’s battery usage and provide a magical experience. Google Fit uses a mix of sensors(Accelerometer, Step counter, Significant Motion counter), Machine Learning and heuristics to get the data right. Our algorithm is pretty similar to … Read more

How can I find distance traveled with a gyroscope and accelerometer?

Basic calculus behind this problem is in the expression (and similar expressions for displacements in y and z) and basic geometry is the Pythagorean theorem So, once you have your accelerometer signals passed through a low-pass filter and binned in time with sampling interval dt, you can find the displacement in x as (pardon my … Read more