Android dim screen down problem
This code dims the screen down开发者_运维技巧, and it works for android 2.2 units. But when i tried it on my emulator(2.3) and on my friend's phone(2.3), i went to lock screen.
Any ideas why, And how i should do to get it work with 2.3?
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 0;
getWindow().setAttributes(lp);
Kind of an old question at this point, but the emulator does not support screen dimming, and that behavior is just a glitch, mine does the same thing on 2.1, 2.2 etc on the emulator.
As to 2.3, I have not seen that. Have you tried to set the 0 to something like 0.01 instead, I have read (though never seen) that on some devices setting it to zero does this, and actually on the emulator if you use 0.01 it will not go to lock screen, though it still does nothing of course (unsupported behavior)
You can also try and logically or in the following
lp.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
Though counter intuitive I have read this keeps the screen touch enabled on devices that go to black when set to 0, and stops the problem your friends phone is exhibiting as well.
Quite honestly with all of the different results reported on different OS versions and platforms I am staying away from the screenBrightness setting since it seems pretty unreliable.
精彩评论