Eric Bergman-Terrell's Blog

Android Programming Tip: Light Sensor is Disabled on Kindle Fire
February 26, 2012

I just got a new case for my Kindle Fire. It's pretty good for the US $22.70 that I paid for it (including shipping).

The case has a large circular hole in the top, left corner. After doing some research, I found that this hole is for the Kindle Fire's ambient light sensor. My Kindle is running version 6.2.2_user3205220 of the operating system, and the light sensor is not used to automatically control the display brightness, even though Amazon's FAQ states that a light sensor is supported.

I had hoped to write an app to address this issue, but the light sensor appears to be completely disabled, at least in operating system version that I'm running. I hope Amazon will see the light, and correct this issue in the future.

Here's the code I wrote to determine if the light sensor is accessible:

package com.ericbt.AutoDimmer;

import java.util.List;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;

public class AutoDimmerActivity extends Activity {
	private SensorManager sensorManager;
	private SensorEventListener sensorEventListener;
	private Sensor lightSensor;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

	@Override
	protected void onPause() {
		Log.i("AutoDimmer", "onPause");
		
		sensorManager.unregisterListener(sensorEventListener, lightSensor);
		
		super.onPause();
	}

	@Override
	protected void onResume() {
		Log.i("AutoDimmer", "onResume");

		initialize();
		
		sensorManager.registerListener(sensorEventListener, lightSensor, SensorManager.SENSOR_DELAY_UI);
		
		super.onResume();
	}
	
	private void initialize() {
		Log.i("AutoDimmer", "initialize");
		
		if (sensorManager == null) {
			Log.i("AutoDimmer", "initialize, initializing");
			
	        sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
	        lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
	        
	        List allSensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
	        
	        for (Sensor sensor : allSensors) {
	        	Log.i("AutoDimmer", String.format("Sensor: %s %d", sensor.getName(), sensor.getType()));
	        }
	        
	        if (lightSensor == null) {
	        	Log.i("AutoDimmer", "Light Sensor: NULL");
	        }
	        else {
		        Log.i("AutoDimmer", String.format("Light Sensor: %s %s", lightSensor.getName(), lightSensor.getVendor()));
		        
		        sensorEventListener = new SensorEventListener() {
					public void onSensorChanged(SensorEvent event) {
						StringBuilder message = new StringBuilder("onSensorChanged ");
						
						for (float value : event.values) {
							message.append(value);
							message.append(' ');
						}
						
						
						Log.i("AutoDimmer", message.toString());
					}
					
					public void onAccuracyChanged(Sensor sensor, int accuracy) {
						Log.i("AutoDimmer", "onAccuracyChanged");
					}
				};
	        	}
		}
	}
}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ericbt.AutoDimmer"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.hardware.sensor.light"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".AutoDimmerActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Four sensors are accessible to the app, but not the ambient light sensor:

Kindle Fire Sensors

Keywords: Android, Kindle Fire, Amazon, Sensors, Light Sensor, Sensor.TYPE_LIGHT, 6.2.2_user3205220

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
Vault 3 Security EnhancementsOctober 24, 2023
Vault 3 is now available for Apple OSX M2 Mac Computers!September 18, 2023
Vault (for Desktop) Version 0.77 ReleasedMarch 26, 2023
EBTCalc (Android) Version 1.44 is now availableOctober 12, 2021
Vault (Desktop) Version 0.72 ReleasedOctober 6, 2021
EBT Compass is Now Available for Android DevicesJune 2, 2021
Convert a Windows 10 Notebook into a High-Capacity Photo FrameApril 3, 2021