How to make android phone flashlight blink?

前端 未结 3 380
盖世英雄少女心
盖世英雄少女心 2021-01-25 05:11

I am trying to make the LED flashlight of android phone blink based on binary code like if char = 1 turn LED light on else if char = 0 turn LED off.

if ( char ==         


        
3条回答
  •  时光说笑
    2021-01-25 06:08

    Try this :

    String myString = "0101010101";
    long blinkDelay = 50; //Delay in ms
    for (int i = 0; i < myString.length(); i++) {
       if (myString.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();
       }
    }
    

    Without the "Thread.sleep()" your code is probably too fast.

提交回复
热议问题