简体   繁体   English

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

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

I've got the following problem: My Flashlight app works fine on my Samsung Galaxy S2 but unfortunately not on the Samsung Galaxy Nexus (problem: flashlight ignores the button-click -> no reaction, no light, no crash, no exception). 我有以下问题:我的手电筒应用程序在我的三星Galaxy S2上工作正常但不幸的是没有在三星Galaxy Nexus上(问题:手电筒忽略按钮点击 - >没有反应,没有光线,没有崩溃,也没有异常)。 I've read "LED flashlight on Galaxy Nexus controllable by what API?" 我读过“Galaxy Nexus上的LED手电筒可以通过哪种API控制?” here in stackoverflow but it did not help me since my problem still occures. 这里在stackoverflow但它没有帮助我,因为我的问题仍然发生。 This is my code-snippet to control the light: 这是我控制灯光的代码片段:

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();
            }
        }}); 

Any ideas? 有任何想法吗? For the sake of completeness - these are the permissions I added to the Androidmanifest.xml: 为了完整起见 - 这些是我添加到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"/>

Can someone help? 有人可以帮忙吗?

Kind regards, CarpeTemporem 亲切的问候,CarpeTemporem

I also had the same problem, but I was trying to turn on the LED from a Service, so I couldn't use a 1x1 SurfaceView. 我也遇到了同样的问题,但我试图从服务中打开LED,所以我无法使用1x1 SurfaceView。 Here's what I did to make it work. 这就是我做的工作。

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 was added in API Level 11 (Android 3.0) so it will only work on Honeycomb or newer. SurfaceTexture在API Level 11(Android 3.0)中添加,因此它只适用于Honeycomb或更新版本。 For older API levels you can stick with the SurfaceView trick in the other answer. 对于较旧的API级别,您可以在另一个答案中坚持使用SurfaceView技巧。

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

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

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