나는 기록 된 파일에 가속도계 데이터를 기록해야하는 프로젝트를하고있다. 누구든지 다음 코드를 통해 나를 도울 수 있습니까? 가속도계 데이터를 기록하기 위해 다음 코드에 추가해야하는 안드로이드 코드는 무엇입니까? 나는 매 10 밀리 세컨드마다 데이터를 얻을 수 있기를 희망한다. 어떤 도움이라도 대단히 감사합니다. 당신이 데이터를 수신하는 속도는 데이터가 콜백을 트리거 이벤트에 의해 제공되는 한, 운영 체제의 재량에 의존 될 것입니다 그건밀리 초 단위로 가속도계 데이터를 기록하는 Android 코드는 무엇입니까?
package com.example.helloandroid;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class AccActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
TextView xCoor; // declare X axis object
TextView yCoor; // declare Y axis object
TextView zCoor; // declare Z axis object
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
xCoor=(TextView)findViewById(R.id.xcoor); // create X axis object
yCoor=(TextView)findViewById(R.id.ycoor); // create Y axis object
zCoor=(TextView)findViewById(R.id.zcoor); // create Z axis object
sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
// add listener. The listener will be HelloAndroid (this) class
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
/* More sensor speeds (taken from api docs)
SENSOR_DELAY_FASTEST get sensor data as fast as possible
SENSOR_DELAY_GAME rate suitable for games
SENSOR_DELAY_NORMAL rate (default) suitable for screen orientation changes
*/
}
public void onAccuracyChanged(Sensor sensor,int accuracy){
}
public void onSensorChanged(SensorEvent event){
// check sensor type
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
// assign directions
float x=event.values[0];
float y=event.values[1];
float z=event.values[2];
xCoor.setText("X: "+x);
yCoor.setText("Y: "+y);
zCoor.setText("Z: "+z);
}
}
}
StackOverflow는 프로그래밍 관련 질문입니다. 이것은 질문이 아닙니다. – CommonsWare
죄송합니다. 주제를 수정하고 질문을 변경했습니다. 매우 감사합니다. – Newbie