【问题标题】:LED Flashlight does not work on Samsung Galaxy NexusLED 手电筒不适用于三星 Galaxy Nexus
【发布时间】:2012-03-19 08:12:07
【问题描述】:

我遇到了以下问题: 我的手电筒应用程序在我的三星 Galaxy S2 上运行良好,但不幸的是在三星 Galaxy Nexus 上无法运行(问题:手电筒忽略按钮点击 -> 没有反应,没有灯光,没有崩溃,也不例外)。我读过“Galaxy Nexus 上的 LED 手电筒可由什么 API 控制?”在stackoverflow中,但它对我没有帮助,因为我的问题仍然存在。 这是我控制灯光的代码-sn-p:

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

【问题讨论】:

  • 我也想知道

标签: android led flashlight


【解决方案1】:

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

【讨论】:

  • new SurfaceTexture(0) 在我的 Nexus 5 running stock Android 5.1 上为我工作,谢谢!
【解决方案2】:

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

【讨论】:

  • 1px/1px表面视图是什么意思
  • @LastWarrior Surface View 具有 1px 高度和 1px 宽度放置在某处并调用 surfaceview 的回调
  • @all 那些想知道 Surface 视图的人,这个答案澄清了这一点:stackoverflow.com/questions/8876843/…
  • 但是它仍然不能在 SGSII xD 上工作......但是在 Sony XPeria S 上工作 - 但可能它也可以在没有表面材料的情况下工作。
  • @GeorgeSpasov 我可以在活动中实现 Surface View 如何为小部件执行此操作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多