-
좌표 소스과거...../개발일지 2010. 3. 9. 01:46
package com.zyapyo;
import android.app.Activity;
import android.content.Context;
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 MainActivity extends Activity {
private SensorManager sm;
private TextView a = null;
float mOrientationValue;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
a= new TextView(this);
setContentView(a);
sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
sm.registerListener(mSensorListener, sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) ,SensorManager.SENSOR_DELAY_FASTEST);
}
public void onStop(){
if(sm != null)
sm.unregisterListener(mSensorListener);
super.onStop();
}
public void onResume(){
super.onResume();
if(sm==null)
//sm = (SensorManager)getSystemService(SENSOR_SERVICE);
sm.registerListener(mSensorListener, sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) ,SensorManager.SENSOR_DELAY_FASTEST);
}private final SensorEventListener mSensorListener = new SensorEventListener(){
public void onSensorChanged(SensorEvent event) {
float x = event.values[2];
if(x < -8&& x >-11 &&event.accuracy == Sensor.TYPE_ORIENTATION){
a.setText("z좌표:" + x);
}
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
};
}