check Sensor Light - Android Hardware

Android examples for Hardware:Sensor

Description

check Sensor Light

Demo Code

/*// w  w  w.j a  v a2s  . c o m
 *  Copyright(c) 2013- AndroboGroup, All rights reserved.
 */
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Build;

public class Main{
    static final String TAG = "CheckUtil";
    
    public static boolean checkSensorLight(Context context) {
        LogUtil.d(TAG, "[IN ] checkSensorLight()");

        boolean result;

        SensorManager sensorManager = (SensorManager) context
                .getSystemService(Context.SENSOR_SERVICE);

        List<Sensor> sensors = sensorManager
                .getSensorList(Sensor.TYPE_LIGHT);

        if (0 < sensors.size()) {
            result = true;
        } else {
            result = false;
        }

        LogUtil.d(TAG, "result:" + result);
        LogUtil.d(TAG, "[OUT] checkSensorLight()");
        return result;
    }
}

Related Tutorials