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

Car*_*us_ 8 android led flashlight

我有以下问题:我的手电筒应用程序在我的三星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();
            }
        }}); 
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?为了完整起见 - 这些是我添加到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"/>
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

亲切的问候,CarpeTemporem

Rah*_*med 17

我也遇到了同样的问题,但我试图从服务中打开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.");

}
Run Code Online (Sandbox Code Playgroud)

SurfaceTexture在API Level 11(Android 3.0)中添加,因此它只适用于Honeycomb或更新版本.对于较旧的API级别,您可以在另一个答案中坚持使用SurfaceView技巧.


Geo*_*sov 4

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

  • 1px/1px 表面视图是什么意思 (4认同)