Android screen brightness that doesn't crash

六月ゝ 毕业季﹏ 提交于 2019-12-24 09:49:21

问题


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 screen brightness?


回答1:


The correct way to set attributes is with setAttributes():

WindowManager.LayoutParams lp = this.getWindow().getAttributes();
lp.screenBrightness = 1;
this.getWindow().setAttributes(lp);



回答2:


You can try the value that is almost 1. For example: 0.999.




回答3:


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.



来源:https://stackoverflow.com/questions/6589412/android-screen-brightness-that-doesnt-crash

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