相机LED闪光灯无法在一台Android设备上运行

时间:2014-10-09 16:21:03

标签: android flashlight

我实现了一个切换闪光灯的功能,但事实证明一个设备有一个奇怪的行为:阿尔卡特POP S3 One Touch。

我在其他设备上尝试过相同的代码,例如

  • Samsung Note 3(OFW(rooted)4.4.2) - >无瑕疵
  • Samsung Galaxy S2(OWF 4.2.2) - >无瑕疵
  • Samsung Galaxy S2(Cyanogenmod 4.2.2) - >打开/关闭时有些延迟
  • 阿尔卡特POP S3 x5050(OFW 4.3):

    作为释放:有时没有,有时是短暂的闪光

    在调试时:有时它神奇地起作用,有时候什么也没有,有时短的LED闪光......

我的代码有问题吗?

//classmember:
//Camera camera = null;
public Boolean toggleLight() {
    // check if camera is present and has flash support
    Boolean hasFlash = context.getApplicationContext().getPackageManager()
            .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

    if (hasFlash) {
        if (camera == null) {
            try {
                // create camere instance (only when facing_back camera is
                // present)
                camera = Camera.open();
            } catch (Exception e) {
                Log.e(TAG, e.getLocalizedMessage());
                return false;
            }
        }
        // get camera infos
        Parameters params = camera.getParameters();
        // get flash status as string
        String isFlashOn = params.getFlashMode();
        if (isFlashOn.equals(Parameters.FLASH_MODE_OFF)) {
            // only gets here if flash is "off"
            params = camera.getParameters();
            // turn on the flash light
            params.setFlashMode(Parameters.FLASH_MODE_TORCH);
            // LED should turn on here
            camera.setParameters(params);
            // should help on some devices, but not important(?)
            camera.startPreview();
            return true;
        } else {
            // all other cases would release the camera to make it available
            // in a second try
            params.setFlashMode(Parameters.FLASH_MODE_OFF);
            // turn flash off
            camera.setParameters(params);
            // stop preview if started
            camera.stopPreview();
            // release the camera resources
            camera.release();
            camera = null;
            return false;
        }
    } else {
        return false;
    }
}`

0 个答案:

没有答案