Altenative way to detect screen off/on - android

Is there an alternative way to detect screen on/off in Android?
I'm currently using ACTION_SCREEN_ON and ACTION_SCREEN_ON intents catched with a receiver, but in API 17 it's bugged (in combination with proximity wake lock).

Related

Does android system send broadcast when the phone is locked?

I know that there is a system broadcast called android.intent.action.SCREEN_OFF, but I want to receive broadcast when user lock his phone not screen off.
I am developing an application that can tell user how long his phones is locked.
I don't see the broadcast you're asking for in the list of available broadcasts listed here https://developer.android.com/about/versions/11/reference/broadcast-intents-30). However, you could use the ACTION_SCREEN_OFF broadcast, and in its onReceive(), use one of the KeyguardManager class's methods to check if the device is locked. The method used would depend on your API version. For example, isKeyguardSecure() supports API 16 and above.

Android: detect reason for wakeup

My BroadcastReceiver listens for ACTION_SCREEN_ON events and works well. But is there any way for me to discover what or who has been waking up the phone? Was it the power button? Was it the alarm clock? Was it XYZ?

Detect Device Wakeness In Android

I'm trying to create a service that run in background in android.. That service should work only when the device is on sleep (Means that screen is off)..
I think that can be done using a service but I don't know how to detect if the phone is awake or not.. Any Idea ? Thanks..
For screen on-off state, you can try with ACTION_SCREEN_ON and ACTION_SCREEN_OFF intents, as shown in this blog post:
http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/
From here : How to detect whether screen is on or off if API level is 4?

What can android listen for while asleep?

I can't find a list of events that can be listened for while a device is sleeping.
For example, it is possible to use LocationListener while asleep.
My goal is to detect when a user is in his car by at least one of the
following methods, which will then wake the phone:
NFC tag on car dock
Bluetooth-enabled car radio in range
But failing those, I'm open to ideas.
Thanks
The best idea so far is to wake the phone periodically as per this link:
Android - periodically wake up from standby mode?
As per the documentation, I could wake the phone up and just use the CPU, while keeping the screen off.
But there might be disadvantages, perhaps there is a better way.
You should create a brodcast receiver and register specific actions.
An example to detect a boot: Android -Starting Service at Boot Time.

Replacing ACTION_SCREEN_ON withy ACTION_USER_PRESENT?

I have a long-running service listening for sensor input. To conserve battery power, I've stopped the sampling of the sensors on ACTION_SCREEN_OFF and started it back up again on ACTION_SCREEN_ON.
Often, however, I just turn my phone on for a quick glance at the clock on the lock-screen (to check the current time) and then turn it off again without unlocking the phone. In that case, there's no reason to spin up the sensors just to shut then down again at once.
So therefore I tried replacing ACTION_SCREEN_ON with ACTION_USER_PRESENT in my broadcast listener. This worked fine except for one special case: When the screen goes off and I press the power button (or home button) at once, the lock screen is skipped. And then the ACTION_USER_PRESENT is never received, only the ACTION_SCREEN_ON.
Is there a way for me broadcast receiver, upon receiving an ACTION_SCREEN_ON to know if the screen-lock is active and to expect a ACTION_USER_PRESENT later? Or if the lock-screen is skipped, not to wait upon ACTION_USER_PRESENT and go ahead and restart the sampling at once?
Till Android 4.4, if screen is turned on and lock screen is disabled, only ACTION_SCREEN_ON is fired. From Android 5.0, in this case, both ACTION_SCREEN_ON and ACTION_USER_PRESENT are fired.

Categories

Resources