How to use Shake API in iPhone SDK 3.0?

The APIs you are looking for are in UIResponder: – (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; – (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event; – (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event; Generally you just implement this: – (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.type == UIEventSubtypeMotionShake) { //Your code here } } in your UIViewController subclass (UIViewController is a subclass of UIResponder). Also, you want to … Read more

how to calculate phone’s movement in the vertical direction from rest?

If you integrate the acceleration twice you get position but the error is horrible. It is useless in practice. Here is an explanation why (Google Tech Talk) at 23:20. I highly recommend this video. Now, you do not need anything accurate and that is a different story. The linear acceleration is available after sensor fusion, … Read more

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

Filtering accelerometer data noise

The samples from Apple’s SDK actually implement the filtering in an even simpler way which is by using ramping: //ramp-speed – play with this value until satisfied const float kFilteringFactor = 0.1f; //last result storage – keep definition outside of this function, eg. in wrapping object float accel[3]; //acceleration.x,.y,.z is the input from the sensor … Read more

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