- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我遇到了以下问题:我的手电筒应用程序在我的 Samsung Galaxy S2 上运行良好,但不幸的是在 Samsung Galaxy Nexus 上运行不正常(问题:手电筒忽略按钮单击 -> 无 react 、无光、无崩溃、无异常)。我读过“Galaxy Nexus 上的 LED 手电筒可由什么 API 控制?”在 stackoverflow 中,但它对我没有帮助,因为我的问题仍然存在。这是我控制灯光的代码 fragment :
final Button FlashLightControl = (Button)findViewById(R.id.ledbutton);
FlashLightControl.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View arg)
{
if(camera != null)
{
//in case light is on we will turn it off
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
camera.stopPreview();
camera.release();
camera = null;
}
else
{
// light is off - we turn it on
camera = Camera.open();
parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
camera.startPreview();
}
}});
有什么想法吗?为了完整起见 - 这些是我添加到 Androidmanifest.xml 的权限:
<uses-feature android:name="android.hardware.camera.flash" />
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
有人可以帮忙吗?
亲切的问候,及时行乐
最佳答案
我也遇到了同样的问题,但我试图通过服务打开 LED,所以我无法使用 1x1 SurfaceView。这是我为让它发挥作用所做的工作。
private void turnLEDOn() throws IOException
{
// In order to work, the camera needs a surface to turn on.
// Here I pass it a dummy Surface Texture to make it happy.
camera = Camera.open();
camera.setPreviewTexture(new SurfaceTexture(0));
camera.startPreview();
Parameters p = camera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
}
private void turnLEDOff()
{
if (camera != null)
{
// Stopping the camera is enough to turn off the LED
camera.stopPreview();
camera.release();
camera = null;
} else
throw new NullPointerException("Camera doesn't exist to turn off.");
}
SurfaceTexture 是在 API 级别 11 (Android 3.0) 中添加的,因此它只能在 Honeycomb 或更新版本上工作。对于较旧的 API 级别,您可以坚持使用其他答案中的 SurfaceView 技巧。
关于android - LED 手电筒不适用于 Samsung Galaxy Nexus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9505945/
嘿,我 wounderd 如果有什么。我可以继续阅读以改进此代码的突击队吗?至少它现在可以工作,但需要做一些微调:) 如您所见,代码非常困惑且难以阅读。希望有人能帮忙。 提前谢谢。 int potPi
我使用 AVR 作为微 Controller ,ATMEGA8 作为处理器(在微 Controller 内部)。带有微 Controller 的电路板有 4 个 LED。我能够刻录程序并点亮 LEDS
谁能解释一下两者之间的关系 LED 像素密度, LED像素高度和宽度 , 和 分辨率在创建模拟器时方法很详细。。并在启动时再次默认值:皮肤尺寸、密度;缩放密度以实现大小? 最佳答案 像素密度:每英寸像
我有一个由大小为 64*64 的 LED 组成的阵列。每个 LED 都可以点亮各种颜色,并且可以非常快速地改变颜色。我的最终目标是:对于网络摄像头接收到的每一帧,我希望能够从帧中“提取”LED 数组,
我正在使用 Arduino Uno 软件进行编码,但遇到了问题。我试图以随机顺序打开 8 个 LED,然后立即将它们全部关闭。我的问题是 LED 会多次点亮相同的 LED,但最终不会全部点亮。这使得电
当我使用Ethernet.begin(mac,ip)时,LED灯不会打开和关闭。但是当我不使用那条线时它就可以工作。但我需要使用以太网和 UPP 模块来打开和关闭。我怎样才能? 板卡型号:以太网08T
我试图顺时针和逆时针方向点亮我的 LED 灯。我使用mpu6050作为LED的方向控制。我检查了我的 mpu6050 驱动代码,它们没问题。顺时针方向工作时效果很好,所有 LED 灯均呈红色亮起。像这
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
我是一名优秀的程序员,十分优秀!