Java tutorial
//package com.java2s; /* * Copyright (C) Stichting Akvo (Akvo Foundation) * * This file is part of Akvo Caddisfly. * * Akvo Caddisfly is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Akvo Caddisfly is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Akvo Caddisfly. If not, see <http://www.gnu.org/licenses/>. */ import android.content.Context; import android.content.pm.PackageManager; import android.hardware.Camera; import android.support.annotation.NonNull; public class Main { /** * Checks if the device has a camera flash * * @param context the context * @return true if camera flash is available */ public static boolean hasCameraFlash(@NonNull Context context, @NonNull Camera camera) { boolean hasFlash = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); try { Camera.Parameters p; if (hasFlash) { p = camera.getParameters(); if (p.getSupportedFlashModes() == null) { hasFlash = false; } else { if (p.getSupportedFlashModes().size() == 1 && p.getSupportedFlashModes().get(0).equals("off")) { hasFlash = false; } } } } finally { camera.release(); } return hasFlash; } }