MakiPong
- Forum posts: 1
Nov 29, 2014, 9:06:04 AM via Website
Nov 29, 2014 9:06:04 AM via Website
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.authenticate_layout);
sm=(SensorManager) getSystemService(SENSOR_SERVICE);
accelerometer=sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
Button sigBtn = (Button) findViewById(R.id.t_signatureBtn);
sigBtn.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN: //PRESSSED
accStart();
break;
case MotionEvent.ACTION_UP: //RELEASED
accStop();
break;
}
return true;
}
protected void accStart(){
sm.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
}
protected void accStop(){
sm.unregisterListener(this);
}
@Override
public void onSensorChanged(SensorEvent event) {
TextView acceleration = (TextView) findViewById(R.id.t_acceleration);
acceleration.setText("X: "+ event.values[0] +
"\nY: " + event.values[1] +
"\nZ: " + event.values[2]);
}
I have an apps that required Accelerometer sensor with onTouchListener implemented to registerSensorListener and stop the accelerometer once released.
I used SENSOR_DELAY_NORMAL to capture data. Speed can be monitored in the Textbox I set in onSensorchanged.
The bug I encountered was sometime I get SENSOR_DELAY_FASTEST speed instead of DELAY_NORMAL. Anyone have any idea what is happening? The phone I using is LG NEXUS 5. For example, I triggered the accelerometer, the speed is going on 5 data per seconds, then at the 5th seconds, it's speed changed to DELAY_FASTEST for few seconds then return back to DELAY_NORMAL.
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.