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!
Related
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.
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
i am currently collecting information, if it is possible to make some kind of quickdraw-application for emergency purposes; i want to get the device to start a customized camera-intent once some certain key-combo is pressed.
I have check quite some information on the topic already, but it is still not clear to me how doable this whole idea is.
So far i figured, that it is not meant to be by android-design. My first idea was to build some kind of InputService and make it teach the hard power-button to listen for a triple-click. But the Services arent allowed to catch KeyEvents. So, the volume-button is out of the equasion aswell.
Then i came across the idea reacting on the SCREEN ON/OFF event, but 80% of the ppl say that it is not going to work, while 20% state, that they got it. But im not really sure if they really did it.
Last but not least the question, if it is possible to launch this customized-camera-intent/application out of the locked mode.
resumé: i need to check if its possible in general to launch this camera-app (that does some quick fotos for emergency purposes) while phone is in the pocket in lock-mode. Anybody got some opinion for me? thx
The solution is to setup a BroadcastReceiver that is listening for the SCREEN_ON-Event. I did this one inside a backgroundservice that was waiting for at least two SCREEN_ON-Events within a short period of time. (less than two events obviously can't work)...
The Service then dismissed the Keyguard and was able to even pass past password/gesture and run the App. Funny fact: closing the app does pop back to desktop still beeing logged in.
I did this at Android 4.2.. Sources told me that dismissing the keyguard is not working with current Android-versions no more.
I have a service that detects when the display of my Android phone is turned on or off. When turned off, the service calls an activity that uses dispatchKeyEvent to detect when the volume up button has been pressed. Unfortunately, apparently the activity can't do this when the screen is off. (See this post.)
I've noticed, though, that something at some level is detecting that event, since the following LogCat message appears when I press the volume-up button when the screen is off: "CatService: Return current sInstance". The message seems to be device specific, since on a different device something different appears in the log, but I'm really only concerned about the first device.
I've done some research into CatService, but haven't found much and can't figure out how I might be able to use it, or whatever is generating the log message, to detect the volume up button press. I'd appreciate any light that anyone can shed on this.
The only way to keep detecting things like this when the screen is off is to acquire a WakeLock that will allow the screen to turn off, and still let your app function. However, this drains the battery life quite a bit, and should only be used when absolutely necessary.
In this case, you will need a PARTIAL_WAKE_LOCK.
I am working on an application that monitors phone use (specifically, what time its being used). Presently, I log times of phone calls, SMSs, MMSs, Screen turning on, screen turning off, and keygaurd unlocking. Now I want to determine when the user does any interaction other than whats listed above. Like:
1) Application use (Detect when an application is launched by the user and/or when it is actively being used by the user)
For this I have been playing with the Activity Manager but there does not seem to be a good way to get the information I need. It has information about whats in the foreground, background and what services are running, but lacks information on the amount of use, time of use, time of application launch, ect.
2) General Screen Interaction (Detect when a user is interacting with the screen in any/all ways)
I have yet to find any way to detect any form of general screen or keyboard interaction while my activity is not in the foreground. Any help here would be appreciated.
3) Other (I am open to other 'events' that would represent a user interacting with their phone)
I am open to other ideas about what I could possible look for when detecting user activity.
Presently, I log times of phone calls, SMSs, MMSs, Screen turning on, screen turning off, and keygaurd unlocking.
Note that your SMS/MMS support is dependent upon an undocumented/unsupported API and may not work on all devices or in future versions of Android.
Detect when an application is launched
Fortunately, there are no broadcasts for this, to help limit the scope of spyware.
General Screen Interaction (Detect when a user is interacting with the screen in any/all ways)
Fortunately, there is no way to determine this, to help limit the scope of spyware.