美文网首页
Ambient light sensor

Ambient light sensor

作者: UnityAsk | 来源:发表于2016-09-23 17:03 被阅读114次

This is a bit of a lie: Apple does not expose any direct ambient light sensing API to developers, so this demo uses screen brightness as a proxy.
This relies on the user having auto brightness enabled, which isn’t always a given (and there’s no easy way to detect if that’s on, either).

ios 不支持获取环境亮度。
androidAPI支持。

<code>
package com.example.testlightambient;
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 SensorActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mPressure;

@Override
public final void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Get an instance of the sensor service, and use that to get an instance of
// a particular sensor.
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
}

@Override
public final void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do something here if sensor accuracy changes.
}

@Override
public final void onSensorChanged(SensorEvent event) {
float millibars_of_pressure = event.values[0];
// Do something with this sensor data.
}

@Override
protected void onResume() {
// Register a listener for the sensor.
super.onResume();
mSensorManager.registerListener(this, mPressure, SensorManager.SENSOR_DELAY_NORMAL);
}

@Override
protected void onPause() {
// Be sure to unregister the sensor when the activity pauses.
super.onPause();
mSensorManager.unregisterListener(this);
}
}
</code>

相关文章

  • Ambient light sensor

    This is a bit of a lie: Apple does not expose any direct ...

  • 传感器

    一、环境光传感器(Ambient Light Sensor) 二、距离传感器(Proximity Sensor) ...

  • Android-P sensor架构和原理分析-1

    1-sensor 基本架构图 Light sensor 属于sensor 其中的一个设备, 因此架构都一样,lig...

  • Ambient Light(环境光)| VRayAmbientL

    概观 VRayAmbientLight是一种特定于V-Ray的光源插件,可用于创建不是来自特定方向的光。它可用于模...

  • 写在前面——光照与材质

    一、四大光照类型1.环境光(Ambient Light) 一个物体即使没有直接被光源照射,但是只要有光线通过其他物...

  • 距离传感器自动待机

    近期,在调试自己的Android2.3.4系统(三星s5pv210平台)时,发现自己的light sensor不仅...

  • Ambient Occlusion

    中文译作环境光遮蔽,它能将画面上的缝隙、洞口、平面的相邻处以及相交的地方加暗,因为在真实情况下,这些地方是光所照射...

  • adb 打印kmsg过滤日志

    adb shell dmesg -w | grep -Ei "sensor1|sensor2"

  • sensor曝光基本原理

    sensor曝光分为逐行曝光和全局曝光。逐行曝光的sensor 技术难度较全局曝光sensor 低,价格便宜,且分...

  • owens相关论文

    Ambient sound provides supervision for visual learning 论文...

网友评论

      本文标题:Ambient light sensor

      本文链接:https://www.haomeiwen.com/subject/wmwtyttx.html