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

自古美人都是妖i 提交于 2020-01-06 08:14:58

问题


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 anybody help to find whether the flashlight is available in lower version

Thanks in advance


回答1:


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,




回答2:


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


来源:https://stackoverflow.com/questions/7145370/how-to-find-flashlight-feature-is-available-or-not-in-device-sdk-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!