Set brightness of flash in Android

十年热恋 提交于 2019-12-13 08:18:59

问题


In my program I tested this:

try {               
    FileWriter mWriter = new FileWriter("/sys/class/leds/flashlight/brightness");
    mWriter.write(125);
    mWriter.flush();
} catch (Exception e) {
    Log.e(TAG, "setFlashlightEnabled failed", e);
}

I have this in the log :

01-13 14:56:30.578: E/test(603): setFlashlightEnabled failed
01-13 14:56:30.578: E/test(603): java.io.FileNotFoundException: /sys/class/leds/flashlight/brightness (Permission denied)
01-13 14:56:30.578: E/test(603):    at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
01-13 14:56:30.578: E/test(603):    at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
01-13 14:56:30.578: E/test(603):    at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
01-13 14:56:30.578: E/test(603):    at java.io.FileOutputStream.<init>(FileOutputStream.java:66)
01-13 14:56:30.578: E/test(603):    at java.io.FileWriter.<init>(FileWriter.java:80)
01-13 14:56:30.578: E/test(603):    at sad.sdsa.sdjahskdhj.TestpuissanceActivity.onClick(TestpuissanceActivity.java:87)
01-13 14:56:30.578: E/test(603):    at android.view.View.performClick(View.java)
01-13 14:56:30.578: E/test(603):    at android.view.View$PerformClick.run(View.java)
01-13 14:56:30.578: E/test(603):    at android.os.Handler.handleCallback(Handler.java)
01-13 14:56:30.578: E/test(603):    at android.os.Handler.dispatchMessage(Handler.java)
01-13 14:56:30.578: E/test(603):    at android.os.Looper.loop(Looper.java)
01-13 14:56:30.578: E/test(603):    at android.app.ActivityThread.main(ActivityThread.java)
01-13 14:56:30.578: E/test(603):    at java.lang.reflect.Method.invokeNative(Native Method)
01-13 14:56:30.578: E/test(603):    at java.lang.reflect.Method.invoke(Method.java:507)
01-13 14:56:30.578: E/test(603):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
01-13 14:56:30.578: E/test(603):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
01-13 14:56:30.578: E/test(603):    at dalvik.system.NativeStart.main(Native Method)

I have tested in ADB Shell this :

echo 125 > /sys/class/leds/flashlight/brightness

It works in root but not in normal mode.

What is the solution to change the flash output without being root?


回答1:


It belongs to system and is being protected by system, so you must be a root to access.Also all Android devices dont have the same flashlight design in structure, sample like: in HTC device, it supports API for handling 3 different brightness level, but others don't...



来源:https://stackoverflow.com/questions/8851897/set-brightness-of-flash-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!