How to change screen dimming time programatically in android? - android

I would like to change system dimming time in my custom application.
My device is set 30s-timeout for sleep.
So if I am in home screen and leave it, it goes dim in 23sec and screen is turned off in 30sec.
Is there any idea for changing screen dimming time for my application?
It's ok to change framework source.
Thanks in advance.

I don't believe android let's you control this option from an application. Of course it lets you set a wake lock for applications to keep the screen on, but I'm pretty sure the screen dimming or "Backlight Timeout" can only be set by the OS.

I don't think there's a programmatic way of modifying the system setting, but you can work around it if the current screen timeout is known...
Figure out how long you want to keep the screen on for and then subtract the current timeout seconds from that time span. The resulting number is how long you should programmatically keep it on via something like View.keepScreenOn

Related

Is it possible to write a script that allows you to change the brightness from the lock-screen?

I am looking to write a basic Android script, for when you hold 2-3 seconds on your device's lock-screen, it will set the brightness to 100. Is this possible on most modern Android devices, and what are some tips I can use to achieve this?
I am specifically looking for these features:
The ability to set the system's brightness to "x" on the lock-screen
The ability to detect if the user has held their finger in a specific spot for "y" amount of time on the lock-screen.
setting brightness with Settings.System.SCREEN_BRIGHTNESS is possible when you acquire proper permission (hints: ACTION_MANAGE_WRITE_SETTINGS, Settings.System.canWrite(context)). BUT on lock screen you can show ONLY Notification, which can't have a seekbar/progressbar controlled by user manually (it can only show progress and on newest OS versions can seek playback if your app is handling audio focus and MediaSession). Instead you can introduce some action buttons, e.g. three options: lowest brightness, auto, max brightness
this is not possible on lock screen. you could achieve this in whole not-locked system (any app) with AccessibilityService, but it will run only when device is unlocked

In Unity3D how turning off screen whithout sleep?

As in Unity3D turn off the screen without entering sleep mode, so that the application continues to work?
I don't believe it's possible to have Unity run in the background.
I don't know if this is still common practice, but in the past, many people simply draw a fully black screen to conserve power.
See: https://forum.unity.com/threads/application-runinbackground-is-not-working-on-android.117723/
Have you looked at - https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationFocus.html
OnApplicationFocus is called when the application loses or gains focus. Alt-tabbing or Cmd-tabbing can take focus away from the Unity application to another desktop application. This causes the GameObjects to receive an OnApplicationFocus call with the argument set to false. When the user switches back to the Unity application, the GameObjects receive an OnApplicationFocus call with the argument set to true.
You could implement this with the gameobjects you want to continue behaving as you like.

How to check for widget Home screen

I want to check whether user is facing the widget Homescreen(ie where the widget are placed) or using some other screen .ie he may be playing game or texting or something else..If user is on some other screen i don't want execute my code..
For instance a clock widget doesn’t need to run once a minute if it’s not visible on the screen. In order to cut down on battery drain it would be really nice if home screen widgets could be informed of their visibility
This is not possible in any reliable fashion. There is a long-standing issue to provide some ability to do this.

controlling screen lock and display brightness from a Service (no Activity)

I've seen two other similar questions, but no answers that work.
Control screen brightness in android using " Background Service"
Android Development: Changing Screen Brightness in Service
I have a background service that is trying to do some custom power management, and needs to be able to independently control the screen locking (either forcing it to lock immediately or keep it from locking) and also the display state (force it to turn off, on, or dim). I'm having a hard time finding such controls. We're developing for a device, so one option is to modify Android source code, but we're trying very hard to avoid that.
I can use PowerManager.WakeLocks to passively suggest screen brightness (and so can anyone else, so it's not guaranteed). This is okay for preventing screen lock and keeping the display on.
I did see a PowerManager.goToSleep() call for forcing the lock screen - that works. But it doesn't force the display to turn off (or something else is preventing that).
Are there any Android OS API's for this? I can't find them in the online dev guide.
To modify the brightness, I'm using
import android.provider.Settings.system;
...
ContentResolver contentResolver = Application.getContext().getContentResolver();
...
System.putInt(contentResolver, System.SCREEN_BRIGHTNESS, value);

Black screen is displaying in Android

I opened my application after I am not doing any kind of operation. I leave the mobile 5 min. After 5 min when I touch the my application it is showing black screen. Is there any way to avoid this idle state?
This is easy to do. Use: getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); in your onCreate method.
There is another way, called a WakeLock, but you really shouldn't use that unless you know what you're doing. See this post from one of the Android designers for more information about WakeLocks and why you shouldn't use them unless you're careful.

Categories

Resources