0
광 센서로 프로젝트를 개발하고 있지만 내 문제는 광 센서가 항상 null을 반환하고 테스트 장치가 삼성 갤럭시 y입니다. 내 의심 : 내 빛 센서 코드가 잘못 되었나요? 아니면 은하계에 광 센서가 없습니까? 코드 뭐가 잘못안드로이드 광 센서 반환 null
package com.example.lightsensor;
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.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class LightSensorActivity extends Activity {
ProgressBar lightMeter;
TextView textMax, textReading;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.light_sensor_layout);
lightMeter = (ProgressBar)findViewById(R.id.lightmeter);
textMax = (TextView)findViewById(R.id.max);
textReading = (TextView)findViewById(R.id.reading);
SensorManager sensorManager
= (SensorManager)getSystemService(Context.SENSOR_SERVICE);
Sensor lightSensor
= sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
if (lightSensor == null){
Toast.makeText(LightSensorActivity.this,
"No Light Sensor! quit-",
Toast.LENGTH_LONG).show();
}else{
float max = lightSensor.getMaximumRange();
lightMeter.setMax((int)max);
textMax.setText("Max Reading: " + String.valueOf(max));
sensorManager.registerListener(lightSensorEventListener,
lightSensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
}
SensorEventListener lightSensorEventListener
= new SensorEventListener(){
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if(event.sensor.getType()==Sensor.TYPE_LIGHT){
float currentReading = event.values[0];
lightMeter.setProgress((int)currentReading);
textReading.setText("Current Reading: " + String.valueOf(currentReading));
}
}
};
}
이 하나가 나를 도울 수 또는 장치는 광 센서를 포함하지 않습니다
나는 코드 아래에 시도?
미리 감사드립니다.
' 라이트 센서가 내장 된 t! –
@K_Anas 갤럭시에는 광 센서가 없습니다. – Dinesh
예 저는 은하계 Y의 기술 시트를 확인해 보셨습니까? –