转自: https://blog.csdn.net/jydzm/article/details/105864194?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

通过对/sys/class/leds/brightness节点写数据来驱动LED灯打开或关闭。

adb shell
echo 125 > /sys/class/leds/brightness (打开LED灯,1-255,值越大,LED越亮)
echo 0 > /sys/class/leds/brightness (关闭LED灯)

以上是通过adb 操作的,接下来是在APP应用中驱动LED灯打开和关闭方法:

方法1:

public void cmdLedOpen() {
    String cmd = "/system/bin/busybox " + "echo 240 >/sys/class/leds/brightness " + "\n";
    try {
        Process exeEcho = Runtime.getRuntime().exec("sh");
        exeEcho.getOutputStream().write(cmd.getBytes());
        exeEcho.getOutputStream().flush();
        Log.d(TAG, " " + cmd);
    } catch (Exception e) {
        Log.d(TAG, "cmdRelayOpen faild");
    }
}

方法2:

public void openLed(){
    try {
        BufferedWriter bw = new BufferedWriter(new FileWriter("/sys/class/leds/brightness"));
        bw.write("250");
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

标签: aosp

添加新评论