开发者

How to find flashlight feature is available or not in device < = sdk 4

I used to find the flashlight is available or not using this code

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

but this code is support for sdk version >= 7 lower version is not supporting. so any开发者_如何学Gobody help to find whether the flashlight is available in lower version

Thanks in advance


Android SDK has Camera class.. you can try getFlashMode method .. If method return null then flash is not support...

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getFlashMode()

I have not tried it,


Try this:

public boolean hasFlash() {
        if (camera == null) {
            return false;
        }

        Camera.Parameters parameters = camera.getParameters();

        if (parameters.getFlashMode() == null) {
            return false;
        }

        List<String> supportedFlashModes = parameters.getSupportedFlashModes();
        if (supportedFlashModes == null || supportedFlashModes.isEmpty() || supportedFlashModes.size() == 1 && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) {
            return false;
        }

        return true;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜