【发布时间】:2014-01-13 16:10:42
【问题描述】:
早上好,
在使用 Microsoft SQL Server 在 C#/ASP.NET 中开发一些应用程序/网站之前,我是 Android 开发的新手。 现在我必须开发一个 Android 应用程序来检测我何时跌倒并发送警报。 我发现了一个这样的例子:
public class MainActivity extends Activity implements SensorEventListener{
private SensorManager sensorManager;
TextView text_X;
TextView text_Y;
TextView text_Z;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this, sensorManager.getDefaultSensor( Sensor.TYPE_ACCELEROMETER ),SensorManager.SENSOR_DELAY_NORMAL );
//Collegamento con le textView del layout
text_X=(TextView)findViewById(R.id.txtXValue);
text_Y=(TextView)findViewById(R.id.txtYValue);
text_Z=(TextView)findViewById(R.id.txtZValue);
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
//L'accelerometro ha cambiato stato
mostraValori(event);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
private void mostraValori(SensorEvent event){
float[] valori=event.values;//array che contiene i valori dell'accelerometro
//modifica del valore delle textView
text_X.setText("Valore X: "+valori[0]);
text_Y.setText("Valore Y: "+valori[1]);
text_Z.setText("Valore Z: "+valori[2]);
}
}
所以我在屏幕上显示了加速度计的 X、Y 和 Z 值。 现在下一步是什么?
谢谢。
【问题讨论】:
标签: android accelerometer gravity