Home » Android » Blink the phone flashlight in a specific order

Blink the phone flashlight in a specific order

Posted by: admin November 1, 2017 Leave a comment

Questions:

I’ve been trying to make a code that could make the flashlight blink in a specific order based on 4 digits that I put on the screen, like a password, but I have a problem when I tried to make the flashlight part, I looked for some codes in the internet but all of then showed some problem.
Edit1. Here is how I would control the flashlight :

 long blinkDelay = 50; //Delay in ms     
        for (int i = 0; i < string1.length(); i++) {      
            if (string1.charAt(i) == '0') { `     
                params.setFlashMode(Parameters.FLASH_MODE_ON);       
            } else {      
                params.setFlashMode(Parameters.FLASH_MODE_OFF);        
            }       
            try {       
                Thread.sleep(blinkDelay);        
           } catch (InterruptedException e) {                   
                e.printStackTrace();                             
            }                                          
        }  

I used:

EditText digito = (EditText) findViewById(R.id.digito1);             
             int digito1 = Integer.parseInt(digito.getText().toString());           
        String string1 = "0000000000";                     
        if (digito1 < 1) {    `                               
            string1 = "0001100000";                         
        } else if (digito1 < 2) {                               
            string1 = "0001100010";                            
        } else if (digito1 < 3) {                         
            string1 = "0001100100";                                
        } else if (digito1 < 4) {                              
            string1 = "0001100110";                           
        } else if (digito1 < 5) {                              
           string1 = "0001101000";                                 
        } else if (digito1 < 6) {                                
            string1 = "0001101010";                                 
        } else if (digito1 < 7) {                                  
            string1 = "0001101100";                                 
        } else if (digito1 < 8) {                                 
           string1 = "0001101110";                           
        } else if (digito1 < 9) {                           
          `  string1 = "0001110000";                        
        } else if (digito1 < 10) {                        
            string1 = "0001110010";                           
    }          

to decide if it would be on or off (0 = off and 1 = on) but when I touch my cellphone the app just closes ( this is when tha flash should blink) and the part that I choose the string1 works.

Answers: