I have an activity that boosts screen brightness
/* turn screen brightness up */
this.getWindow().getAttributes().screenBrightness = 1;
I found out this built in android function crashes some phones.
Is there a more universal way to boost scree开发者_运维问答n brightness?
The correct way to set attributes is with setAttributes()
:
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
lp.screenBrightness = 1;
this.getWindow().setAttributes(lp);
You can try the value that is almost 1
. For example: 0.999
.
If you want touch events to pass through you need to do more than setting brightness.
You need to set view and layout parameters.
view.setFocusable(false);
view.setClickable(false);
view.setKeepScreenOn(false);
view.setLongClickable(false);
view.setFocusableInTouchMode(false);
layoutParams.height = LayoutParams.FILL_PARENT;
layoutParams.width = LayoutParams.FILL_PARENT;
layoutParams.flags = 280; // You can try LayoutParams.FLAG_FULLSCREEN too
layoutParams.format = PixelFormat.TRANSLUCENT; // You can try different formats
layoutParams.windowAnimations = android.R.style.Animation_Toast; // You can use only animations that the system to can access
layoutParams.type = LayoutParams.TYPE_SYSTEM_OVERLAY;
layoutParams.gravity = Gravity.BOTTOM;
layoutParams.x = 0;
layoutParams.y = 0;
layoutParams.verticalWeight = 1.0F;
layoutParams.horizontalWeight = 1.0F;
layoutParams.verticalMargin = 0.0F;
layoutParams.horizontalMargin = 0.0F;
Take a look at my original post.
精彩评论