Screen Dim Event / User Inactivity - android

first of all, I would like to tell you, what I want to do: I want to get some behavior of iOS on my Android device. Of course, it's just a little detail.
The behavior I talk about is on iOS like that:
The user doesn't use the device
After a short time, the device dims its screen.
Now the user has to tap somewhere on the display to reactivate the device.
THIS IS THE BEHAVIOR I WANT If the user taps on the screen, the screen
will just become active again. The tap itself will NOT cause any other action.
On Android, it's almost the same behavior. Except for step 4: If the user taps on the screen to prevent standby, the tap will already cause actions in the app or home screen or wherever you are.
I decided to develop a small Accessibility Service. This service will show an overlay when the device is inactive and dims its display. Clicking on the overlay will just close it. The overlay itself is no problem and it's already working.
My problem is: I don't know how to find out when the display is dimmed because of inactivity.
My ideas are:
Listen to the Intent.ACTION_SCREEN_OFF event (https://developer.android.com/reference/android/content/Intent).
--> It's working. But it's too late :-( The screen is already completely off when the event has been fired.
Check, if the device is inactive/idle.
--> Is there any possibility to get the status of the whole device? I haven't found anything about that.
Or maybe somebody has completely other ideas?
Thanks for your help.
Greetings
Patrick

You can keep the window screen on & using a TimerTask, dim the brightness of the window manually by some % every, say 5 seconds...
Then when the taps on overlay, Increase the brightness

Related

What's the best way to launch a view after device is unlocked?

I'm trying to display a view that the user must dismiss each time they unlock their phone (it's intended to be annoying). It should be able to take a small amount of keyboard input, save it, then return to the previously open activity. I tried having a BroadcastReceiver listen for ACTION_USER_PRESENT and launch my own activity, but then I found out we can no longer listen for implicit intents, or have background services launch activities.
I'm not an Android developer (just trying to build something for my phone), but I did some looking, and I see a few options:
Display a full-screen intent. I think something like scheduling a job to raise a notification whenever the phone is locked, so that the notification appears first thing when they unlock the phone.
Use SYSTEM_ALERT_WINDOW and draw my view as an overlay whenever the phone is unlocked. My only concern with this is how apps like Twilight (which I believe draws an overlay to redden the screen) might interact with it. In those cases, I'd like my overlay to appear at the very bottom.
Are either of those options viable or recommended? Any other suggestions or approaches for how I could accomplish this would be greatly appreciated too. I'm just looking for some guidance on what direction I should pursue.

Detecting reason for the screen turning ON

What I have so far is a Service with a registered BroadcastReceiver for the following actions: ACTION_SCREEN_ON/ACTION_SCREEN_OFF.
So far so good. If the screen goes ON or OFF I get the notification. But this happens for various reasons: user pushes a button (POWER, HOME, etc), battery gets fully charged, incoming call, etc.
What I need is to detect what was the reason for turning the screen ON. And more precisely to detect if it was because of the user pushing power or home button. I've read some opinions that there is no reliable way to do this, but would like to ask again before giving up.
Thanks in advance!

android invasive advertising screen from installed app, how to replicate that?

I installed an app on my android phone to safe lock certain apps with a password. Since I installed it, sometimes, regardless what i'm doing on the phone/which app i'm using, a full size screen with advertising appears and I have to click an "X" to close it or press back/home button.
(Can be that this screen appears randomly only when I digited a password to unlock an app therefore the safe lock app was active let's say, not sure.)
I was anyway wondering what sort of code is used for this? Anyone?
I'd need it for a less despicable cause: in order to show a transparent view with alertdialog when my timer is up and the app is closed, to imitate the original builtin countdown timer.

How to disable unlocking screen programmatically

I need to lock the Android phone when the user leaves a defined WiFi area
I need to prevent the user from unlocking the phone when he/she is out side the defined WiFi area
I need to unlock the phone when user is back to the WiFi area
I guess list items 1 and 3 can be done programmatically.
Is it possible to do the 2nd item?
Locking can be done using this method: How to lock the screen of an android device
Unlocking look here: How to display Activity when the screen is locked?
For your problem 2, i see 2 solutions
a. If the user unlocks the screen, a message is fired: check at that moment if you are in the area and if not, instantly lock again
b. create your own locksreen with no possibility to unlock yourself
I need to prevent the user from unlocking the phone when he/she is out side the defined WiFi area
Fortunately, this is not supported, for obvious security reasons.
You are welcome to create your own home screen that offers different behavior when inside/outside a defined area and use that in lieu of trying to prevent a phone from being unlocked. However, the user is welcome to remove that home screen by booting their device into safe mode and uninstalling your app.
I had done similar thing in past but dont have the code right now so cant help in that respect. What I did is implement the app as Car Dock that will make the Home button override unless car-dock mode is dis-abled. I hope this will help, for code google it you definitely find resources
I guess this will help you out. This is just for Disabling the Lock Programmatically.Disable Screen Lock
private Window w;
public void onResume() {
w = this.getWindow();
w.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
w.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
w.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
super.onResume();
tToast("onResume");
}

Is it possible to get a device to wake up from sleep (screen dark) by detecting a touch to the screen?

I want to get an android device to wake up from sleep or however the state in which the phone gets after a certain amount of inactivity when the screen goes dark, by detecting a touch to the screen instead of clicking on any button.
In the documentation the only thing I have found is the FLAG_TOUCHABLE_WHEN_WAKING flag in WindowManager.LayoutParams and it says:
Window flag: When set, if the device is asleep when the touch screen
is pressed, you will receive this
first touch event. Usually the first
touch event is consumed by the system
since the user can not see what they
are pressing on.
I thought that meant that if the device's screen is turned off and that flag is set for an Activity then it will wake up to the touch (which is what I want it to do). Am I misunderstanding the purpose of this flag? Are there additional implementation details I'm ignoring? Is there some other way?
Am I misunderstanding the purpose of this flag?
AFAIK, yes. There is a slice of time between when the screen turns off and when the device falls asleep. During this time, if the user touches the screen someplace where the window has this flag, the screen turns on again and the inactivity timer is reset.
I can find no other use of this flag in the Android source code.
Is there some other way?
No. If the device is asleep, touch screen events are not registered.

Categories

Resources