Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to check the flash light is available on device?

Tags:

android

How I check the flash light available on device?also want to know how can I On/Off the flash light? I have put the code but not working right now? I search out this
http://gitorious.org/rowboat/frameworks-base/commit/eb9cbb8fdddf4c887004b20b504083035d57a15f
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/com/android/server/LightsService.java#LightsService

Please can tell which I should use?
Thank You.

like image 277
Sameer Z. Avatar asked Feb 07 '11 06:02

Sameer Z.


2 Answers

You can use the following

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

which will return true if a flash is available, false if not.

See http://developer.android.com/reference/android/content/pm/PackageManager.html for more information.

like image 119
Al Sutton Avatar answered Nov 15 '22 08:11

Al Sutton


boolean hasFlash =this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

or

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;
    }
like image 24
reza.cse08 Avatar answered Nov 15 '22 09:11

reza.cse08