繁体   English   中英

LED手电筒不适用于三星Galaxy Nexus

[英]LED Flashlight does not work on Samsung Galaxy Nexus

我有以下问题:我的手电筒应用程序在我的三星Galaxy S2上工作正常但不幸的是没有在三星Galaxy Nexus上(问题:手电筒忽略按钮点击 - >没有反应,没有光线,没有崩溃,也没有异常)。 我读过“Galaxy Nexus上的LED手电筒可以通过哪种API控制?” 这里在stackoverflow但它没有帮助我,因为我的问题仍然发生。 这是我控制灯光的代码片段:

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"/>

有人可以帮忙吗?

亲切的问候,CarpeTemporem

我也遇到了同样的问题,但我试图从服务中打开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 Level 11(Android 3.0)中添加,因此它只适用于Honeycomb或更新版本。 对于较旧的API级别,您可以在另一个答案中坚持使用SurfaceView技巧。

我遇到了同样的问题,并通过使用1px宽度和1px高度的Surface View解决了这个问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM