package com.ShakeT1;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class ShakeT1 extends Activity implements SensorEventListener{
SensorManager sensorManager = null;
Sensor accSensor;
SensorEventListener acc;
TextView outputX;
TextView outputY;
TextView outputZ;
//for orientation values
TextView outputX2;
TextView outputY2;
TextView outputZ2;
Sensor ACCELEROMETER;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
outputX = (TextView) findViewById(R.id.TextView01);
outputY = (TextView) findViewById(R.id.TextView02);
outputZ = (TextView) findViewById(R.id.TextView03);
outputX2 = (TextView) findViewById(R.id.TextView04);
outputY2 = (TextView) findViewById(R.id.TextView05);
outputZ2 = (TextView) findViewById(R.id.TextView06);
ACCELEROMETER = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
@Override
public void onResume() {
super.onResume();
boolean A =sensorManager.registerListener(this,ACCELEROMETER ,SensorManager.SENSOR_DELAY_NORMAL);
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), sensorManager.SENSOR_DELAY_GAME);
}
@Override
protected void onStop() {
super.onStop();
sensorManager.unregisterListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));
sensorManager.unregisterListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION));
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
synchronized (this) {
switch (event.sensor.getType()){
case Sensor.TYPE_ACCELEROMETER:
outputX.setText("x:"+Float.toString(event.values[0]));
outputY.setText("y:"+Float.toString(event.values[1]));
outputZ.setText("z:"+Float.toString(event.values[2]));
break;
case Sensor.TYPE_ORIENTATION:
outputX2.setText("x:"+Float.toString(event.values[0]));
outputY2.setText("y:"+Float.toString(event.values[1]));
outputZ2.setText("z:"+Float.toString(event.values[2]));
break;
}
}
}
}
/////////////////////////XML///////////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/TextView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x:"
/>
<TextView
android:id="@+id/TextView02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x:"
/>
<TextView
android:id="@+id/TextView03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x:"
/>
<TextView
android:id="@+id/TextView04"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x:"
/>
<TextView
android:id="@+id/TextView05"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x:"
/>
<TextView
android:id="@+id/TextView06"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x:"
/>
<TextView
android:id="@+id/TextView07"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x:"
/>
</LinearLayout>
인터넷에 돌아다니는 소스를 이용해서 간단하게 텍스트 필드에 방향값을 나타내고 싶은데 이상하게 알수없는 이유로 어플리케이션이 꺼졌다는 메시지가 나오네요 ㅠㅠ
고수님들 어느 부분에서 잘못됬는지 알려주세요 ㅠ ..




대충 훓터보니 가속도 센서를 사용하는거 같은데요....
혹시 에뮬단에서 해 보신게 아닌가요..? 단말에서 돌리면.... 될듯도 한데..
그리구.. 이렇게 소스를 올려놓고 왜 안되나요~~ 이렇게 올리시면 잡아주실분 아무도 안계십니다;ㅁ;
로그켓 애러 정보를 올려 주셔야 어떻게든 해결을 해 주시지요...
필독글을 한번 읽어 보시구 로그켓 정보를 올려 주세요