Reputation: 2336
i want to get and move needle on co-ordinates as per user rotates or move device as compass does also as this app is doing already.you can see what i want to say on this link https://play.google.com/store/apps/details?id=com.plaincode.clinometer&hl=en but now at this time i am not able to understand on this context. i am unable to find hint for how to start..is their is any api to get and make it work or need to implement accelerometer on a very extensive level to get it done. please guide me if u have any code or link regarding this..thank in advance
Upvotes: 2
Views: 1988
Reputation: 353
You should start creating an activity that implements SensorEventListener, including the two following methods:
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
// add your code
// event.values[] contains the 3 accelerometer values
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
// add your code
}
As second step, start with the implementation of accelerometers into the Activity:
private SensorManager mSensorManager;
private Sensor mRotationSensor;
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
Then register a sensor listener on it (you could do in onResume):
mSensorManager.registerListener(this, mRotationSensor, 16000);
// 16000 microseconds
and unregister it (in onPause):
mSensorManager.unregisterListener(this);
Please note that, if you want a very accurate measurement of angles and slopes in the 3 dimensions, you should implement a calibration routine of the onboard accelerometers, that usually need a small compensation in gain, offset and angle.
You can read a simple but complete usage of Accelerometers on the free and opensource BasicAirData Clinometer: https://github.com/BasicAirData/Clinometer
The app includes also a calibration routine.
Upvotes: 0
Reputation: 2336
I was looking for this solution more than a year ago and for that somehow i managed to do this similar this way. and source for that which i managed to do is -- link to source
Upvotes: 0