Camera.Parameters.FLASH_MODE_TORCH更换为Android 2.1 [英] Camera.Parameters.FLASH_MODE_TORCH replacement for Android 2.1

查看:2206
本文介绍了Camera.Parameters.FLASH_MODE_TORCH更换为Android 2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个应用程序,需要的LED闪光灯进入手电筒模式。问题是,Android 2.1系统不支持该模式,因此,我不能支持这个平台呢。会不会是一个问题,但我写它为我的未婚夫,她的史诗4G不仅拥有2.1现在。我发现,使用一些未公开的API调用,因此工作的摩托罗拉Droid和这样的一些code样品,但他们不史诗工作。有没有人有哪里可以找到code,应该帮助我得到这个工作的一些建议?

I am trying to write an app that requires the LED flash to go into torch mode. The problem is, Android 2.1 does not support this mode and therefore I cannot support the platform yet. Wouldn't be an issue, but I am writing it for my fiance and her Epic 4G only has 2.1 right now. I found some code samples that use some undocumented API calls and therefore work on the Motorola Droid and such, but they do not work on the Epic. Does anyone have some suggestions on where to look to find code that should help me get this working?

推荐答案

我发现手电筒模式一般是工作正常的2.1,但我有同样的问题与三星史诗,发现它周围的黑客攻击。

I'm finding that torch mode is generally working fine on 2.1 but I had the same problem with the Samsung Epic and found a hack around it.

综观()对三星史诗中运行时通过Camera.getParameters返回的参数,可以我注意到,闪光模式,它声称支持有:闪光模式值=关,开,自动;

Looking at the params returned by Camera.getParameters() when run on the Samsung Epic, I noticed that the flash-modes it claims to support are: flash-mode-values=off,on,auto;

火炬模式没有列出,这意味着它不支持。

torch-mode is not listed, implying it's not supported.

不过,我发现,这种模式仍然接受模式,并会打开LED!坏消息是,当后来设置闪光模式回自动或关闭左侧还亮着指示灯!它不会关闭,直到调用Camera.release()。

However, I found that this model would still accept that mode and WOULD turn the LED on! The bad news was that when later setting the flash-mode back to auto or off left the LED still lit! It will not turn off until you call Camera.release().

我想这就是为什么三星不要将其包含在支持!行了吗?!

I guess that's why Samsung dont include it in the list of supported!?!

所以...我用它来切换火炬在CameraHelper类中的方法是...

So...the method I use to toggle torch in a CameraHelper class is...

/***
 * Attempts to set camera flash torch/flashlight mode on/off
 * @param isOn true = on, false = off
 * @return boolean whether or not we were able to set it
 */
public boolean setFlashlight(boolean isOn)
{
    if (mCamera == null)
    {
        return false;
    }
    Camera.Parameters params = mCamera.getParameters();
    String value;
    if (isOn) // we are being ask to turn it on
    {
        value = Camera.Parameters.FLASH_MODE_TORCH;
    }
    else  // we are being asked to turn it off
    {
        value =  Camera.Parameters.FLASH_MODE_AUTO;
    }

    try{    
        params.setFlashMode(value);
        mCamera.setParameters(params);

        String nowMode = mCamera.getParameters().getFlashMode();

        if (isOn && nowMode.equals(Camera.Parameters.FLASH_MODE_TORCH))
        {
            return true;
        }
        if (! isOn && nowMode.equals(Camera.Parameters.FLASH_MODE_AUTO))
        {
            return true;
        }
        return false;
    }
    catch (Exception ex)
    {
        MyLog.e(mLOG_TAG, this.getClass().getSimpleName() +  " error setting flash mode to: "+ value + " " + ex.toString());
    }
}

使用这个称呼其为如下的活动...

The activities that use this call it as follows...

private void toggleFlashLight()
{
    mIsFlashlightOn = ! mIsFlashlightOn;

    /**
     * hack to fix an issue where the Samsung Galaxy will turn torch on,
     * even though it says it doesnt support torch mode,
     * but then will NOT turn it off via this param.
     */
    if (! mIsFlashlightOn && Build.MANUFACTURER.equalsIgnoreCase("Samsung"))
    {
        this.releaseCameraResources();
        this.initCamera();
    }
    else
    {
        boolean result = mCamHelper.setFlashlight(mIsFlashlightOn);
        if (! result)
        {
            alertFlashlightNotSupported();
        }
    }
}

神奇,使这项工作releaseCameraResources()是调用Camera.release()......然后我不得不重新初始化我所有的摄像头的东西三星设备。

The magic that makes this work in releaseCameraResources() is that it calls Camera.release()....and then I have to reinitialize all my camera stuff for Samsung devices.

不是pretty的,但似乎是工作的大量用户。

Not pretty but seems to be working for plenty of users.

请注意,我确实有手电筒模式不工作与在Nexus One上这个code一份报告,但已经能够钻进去了。这肯定适用于HTC EVO和三星史诗。

Note that I do have a report of torch mode not working at all with this code on Nexus one but have been able to dig into it. It definitely works on HTC EVO and Samsung Epic.

希望这有助于。

这篇关于Camera.Parameters.FLASH_MODE_TORCH更换为Android 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆