1.
2.
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; public class MainActivity extends Activity { private SensorManager sensorManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
Sensor lightSensor = (Sensor)sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); sensorManager.registerListener(new SensorEventListener() { public void onSensorChanged(SensorEvent event) {
String sensorName = event.sensor.getName();
String sensorVendor = event.sensor.getVendor();
float resolution = event.sensor.getResolution();
float power = event.sensor.getPower();
double timestamp = event.timestamp; System.out.println("sensor name--->" + sensorName);
System.out.println("sensor vendor--->" + sensorVendor);
System.out.println("sensor resolution--->" + resolution);
System.out.println("sensor power--->" + power);
System.out.println("timestamp--->" + timestamp); } public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, lightSensor, SensorManager.SENSOR_DELAY_GAME);
}
}