Code example for FileInputStream

Methods: close, read

0
 
        private static final String FLASHLIGHT_FILE = "/sys/class/leds/spotlight/brightness"; 
 
        public boolean getFlashlightEnabled() { 
            try { 
                FileInputStream fis = new FileInputStream(FLASHLIGHT_FILE); 
                int result = fis.read(); 
                fis.close(); 
                return (result != '0'); 
            } catch (Exception e) { 
                return false; 
            } 
        } 
 
        public void setFlashlightEnabled(boolean on) { 
            if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.FLASHLIGHT) 
                    != PackageManager.PERMISSION_GRANTED && 
                    mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST) 
                    != PackageManager.PERMISSION_GRANTED) { 
                throw new SecurityException("Requires FLASHLIGHT or HARDWARE_TEST permission"); 
            }