Android|Android 上层操作底层设备节点

通过对/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"); } }

【Android|Android 上层操作底层设备节点】方法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(); } }

    推荐阅读