Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Light Sensor Value
    primarykey
    data
    text
    <p>So I'm looking for a way to get the current value of the Light Sensor (in Lux obviously) on a button press. Here is the code I'm using to implement control of the light sensor</p> <pre><code>public class SensorActivity extends Activity implements SensorEventListener { private final SensorManager mSensorManager; private final Sensor mLight; int minLux = 0; int currentLux = 0; int maxLux; public SensorActivity() { mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); } protected void onResume() { super.onResume(); mSensorManager.registerListener((SensorEventListener) this, mLight, SensorManager.SENSOR_DELAY_NORMAL); } protected void onPause() { super.onPause(); mSensorManager.unregisterListener((SensorListener) this); } public void onAccuracyChanged(Sensor sensor, int accuracy) { if(sensor.getType() == Sensor.TYPE_LIGHT) { } } public void onSensorChanged(SensorEvent event) { if( event.sensor.getType() == Sensor.TYPE_LIGHT) { } } } </code></pre> <p>I also have this code making the button to call a function</p> <pre><code>&lt;Button android:layout_width="122px" android:id="@+id/widget35" android:text="Start" android:layout_height="wrap_content" android:layout_x="112dp" android:layout_y="249dp" android:onClick="onButtonDown"&gt;&lt;/Button&gt; </code></pre> <p>How would I get the current lux value while the app is running in the background, and how would I get and store the current lux value on button press into <code>int maxLux;</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload