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.
Related
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.
Is it possible to determine if a device (non-rooted) is in use at the moment, even if my app is not in the foreground? Precisely "in use" means the user made touch events in the last 5 seconds or display is on.
If so, what specific rights are required?
Thanks
AFAIK, android security model would not allow you to record touches if your app in not in the foreground.
There are some crude workarounds like overlaying a transparent screen to record touches. Not sure if these work now though.
"in use" means the user made touch events in the last 5 seconds
In Android, that's not practical, short of writing your own custom ROM.
or display is on
In Android, you can find out if the device is in an "interactive" mode or not. This does not strictly align with screen-on/screen-off, as the whole notion of screen-on/screen-off has pretty much fallen by the wayside.
I have a requirement that I have to count that At End of Day how many Time user kept Hand on Android Screen ?
So for that after googling I found that, there is proximity Sensor in Android which senses hand movement without touching screen. Proxymity Sensor is located somewhere on Top of Screen for Accessing object close to phone while attending and cancelling any calls
But I wanted to capture user hand press on Android Screen. What could be better solution ? or can my purpose be fully solved via proximity Sensor only ?
Proxymity Sensor is very rough and used to tell whether mobile device is close to something big as head.
You need to implement hooks for everything that user may touch, and increase your counter, that should be saved/restored when app goes to background and returns.
Note that you only can know about touches within your app.
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
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.