안드로이드 개발 질문/답변
(글 수 45,052)
static SensorManager sm; static SensorEventListener acc; static Sensor accSensor; static double xx, yy, zz; public void surfaceCreated(SurfaceHolder holder) { sm = (SensorManager)getSystemService(SENSOR_SERVICE); //윗줄 SENSOR_SERVICE 가 에러가 납니다 어떻게 하면 좋을까요 ? ㅠㅠ // SensorManager 인스턴스를 가져옴 accSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // 가속도 센서 acc = new accListener(); // 가속도 센서 리스너 인스턴스 sm.registerListener(acc, accSensor, SensorManager.SENSOR_DELAY_GAME); sm.unregisterListener(acc); try { mThread.start(); } catch (Exception e) { RestartGame(); if (isMusic) player.start(); } } private class accListener implements SensorEventListener { public void onSensorChanged(SensorEvent event) { // 가속도 센서 값이 바뀔때마다 호출됨 xx=event.values[0]; yy=event.values[1]; zz=event.values[2]; } public void onAccuracyChanged(Sensor sensor, int accuracy) { } } public boolean allways() { if(xx>0) { mShip.dir = 1; } else if(xx<0){ mShip.dir = 2; } return false; }
이 소스의 문제점좀 가르쳐주세요 왜 안되는지 모르겠습니다... ㅜㅜ 정말 초보라서 잘 모르겠습니다. ㅜㅜ 기본적인 질문이라도 어디에 올려야 할지도 모르겠고.. 아는 싸이트는 여기밖에없고 도움좀 부탁드려요.
getSystemService 메소드는 Context의 추상 메소드 입니다.
뷰에서 그냥 사용할 수 없습니다.
getContext().getSystemService(Context.SENSOR_SERVICE); 로 변경해서 해보세요.