Any other way to set window brightness? - android

I maintain an auto-brightness app which uses an overlay to set screen brightness. The brightness is set through LayoutParams.screenBrightness.
Up to lollipop, I used TYPE_SYSTEM_OVERLAY for overlay type and everything was fine.
However, lollipop sees this overlay type as a threat or something and:
Doesn't turn on the screen automatically at all if such an overlay is present
If overlay is added later, the full screen notification such as alarm or incoming phone call will be suspended and reduced to notification bar
Naturally, this is a huge issue for me.
I have tested other window types and found that TYPE_PRIORITY_PHONE, TYPE_SYSTEM_ALERT, TYPE_TOAST all work (in the sense that they don't cancel the full-screen notification), but they won't respect brightness commands while in lock screen.
Is there any other way I could set screen brightness while in lock screen?

Related

Prevent screen from locking but allow dimming

I'm trying to get my Android app to keep the screen unlocked as long as the app is running. I easily solved this problem with setting this flag - WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON - in each activity.
But now I'd also like to allow the screen to dim and stay dimmed until a touch event is registered. I tried to mess with window object's screenBrightness and dimAmount but none of these worked (no changes in the brightness were made). Any ideas if I can implement this feature?
As a last resort I'd think a black dialog with alpha .5 covering the whole screen would work, but I don't know if this solution will have the same effect as an actual dim, battery-saving wise

screen dimming automatically when switch activity

I'm working on an application to record wounds with the camera2-api. For this I scan a qr-code with the patient data and then start to take picture of the wound. But when the activity (to take pictures) launches it seems like the screen gtes dimmed till I touch the screen and I dont know why
I think its up to the device because I use the same fragment for scanning and to take pictures and when I launch the ScanActivity the issue dosn't accure
What I have already tried
Change the display options of the device (brightness of the
screen adjust automatically to your environment).
Change the power saving mode activation time to 30 minutes
Set the AE state like this
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
and
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
My questions
I'm not sure if the screen gets darker because of the exposure of the camera, the brightness of the screen or maybe the device switch to the
power saving mode.
How can i prevent that?
i got the solution. There was a AlertDialog without a view. At the begin i show the user the number of pictures but if the number is 0 no view added to the alert and that looks like the screen is dimming

How to detect full screen gesture mode in Mi devices programmatically

I am writing an Android application that needs to calculate the height of screen to display content correctly. But the height I got in Mi devices (Mi 9 SE) wasn't correct when switching to full screen gesture mode.
How can I get the real height of the screen, or check if user turned on full screen gesture mode in Mi devices?
I have tried these suggestions.
How to detect full screen gesture mode in android Q
Android: detect navigation bar visibility
Check for navigation bar
After searching and experimenting, I have found the only solution: How to detect full screen gesture mode in android Q.
Instead of using ViewCompat.setOnApplyWindowInsetsListener() function, I just have to create a WindowInsets instance for the current context, then check the getSystemGestureInsets() for each edges. This is how I implemented to make a React Native's native module.
If you need a listener to detect every changes, the solution above has done well on Android app. If you want this listener for React Native, you might want to find another approach, since I haven't made it work.
A very simpler answer:
Don't use DisplayMetrics. Just make any view take full width and height of the screen (MATCH_PARENT) then get it's dimensions, it well give accurate numbers.

Refreshing screen brightness instantaneously

I'm trying to set System Screen Brightness instantaneously. I'm using a service to do that. Here it the code that I'm using.
Settings.System.putInt(cResolver,
Settings.System.SCREEN_BRIGHTNESS, 255);
This code works fine. But it is not instantaneous. The screen brightness value changes but the screen still looks dull. I can confirm this by reading back the screen brightness value and it is 255. If I lock the screen and come back, the screen is fully bright. How can I achieve this that the moment I set the system brightness to the maximum, I see fully bright screen?
BTW, I want to do this using a service and not an activity!
I would take a look at this link, specifically the first answer. It's a bit hackish though.
Changing screen brightness programmatically (as with the power widget)
Essentially you need to force the screen to refresh through starting a dummy activity and then finish() said dummy activity. I would have commented but I don't have enough points.

Make screen go black

Is it possible in Android to make the screen go black? You can set the brightness to a low level but you cannot dim it until it goes black. Of course I could create an activity with just a black screen but would prefer an API that simply turns the screen off but not power down the device.

Categories

Resources