[英]How to check for duration on shake in android?
I have tried this code, but it does not seem to check for shake duration effectively. 我已经尝试过此代码,但它似乎并未有效检查抖动持续时间。 I want to get a farther latitude and longitude when shake for a long time.
我想长时间晃动时能获得更远的经度和纬度。
@Override public void onSensorChanged(SensorEvent event){
ImageView colorBox = (ImageView)findViewById(R.id.colorBox);
TextView latText = (TextView)findViewById(R.id.latText);
TextView lngText = (TextView)findViewById(R.id.longText);
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
float[] values = event.values;
float x = values[0];
float y = values[1];
float z = values[2];
float acclt = (x*x+ y*y+ z*z)/(SensorManager.GRAVITY_EARTH*SensorManager.GRAVITY_EARTH);
long actualTime = System.currentTimeMillis();
if(acclt >2) {
}
}
}
Try Seismic lib: https://github.com/square/seismic 尝试Seismic lib: https : //github.com/square/seismic
Demo app shows how you can use it. 演示应用程序展示了如何使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.