I have service running in background whose job is to detect whenever phone is IDLE for more than certain time then show a popup message with an Image.
I could not find how do I detect that phone is in idle state now.
UPDATE
IDLEness is represented by following three scenarios
1) User inactivity
2) Screen goes off
3) sensors: gyroscope (x,y,z) and accelerometer remains 0 for a defined amount of time.
thanks
leo
1) User has not interacted with phone for certain time
There is no means for you to determine this.
2) Phone screen goes off when not used.
Listen for ACTION_SCREEN_OFF broadcasts.
Related
is there a sensor in android to detect a tap on the device? I have a service and I want to detect when the user touches the phone. He can touch(tap) the screen, back or any other part of the device and it will trigger a function within my service. Is that possible? For example, if I have the device in my pocket, and I want my service to call a certain function when the user tap the phone from outside his pocket. Thanks.
You can use the accelerometer. The accelerometer detects a force on the device, and a tap would cause a force. The trick would be filtering out other forces, such as bouncing when walking.
I want to control my android smartphone that after my son playing games on my phone after a specified time such as half an hour, the phone will be locked unless you submit the right password.
I don't know how to trigger the lock screen process.
How can I implement interrupting the games processes and lock the cellphone?
How unlock and lock screen programatically in android Has some excellent information on immediately calling the lock screen. You could implement a system using an alarm manager to trigger this event.
Here is a good example,
first thing you need to do this, U need to know when the screen gets unlock. So here you go.....
android-detect-phone-unlock-event-screen-on
After that you set a time for 30/40/50 minutes (as you wish).
Once the timer fires, use below link to lock your screen.
lock-phone-screen-programmtically
And your work is done.
I would like to know if there is the possibility that my APP can notice when I clicked the red button (accidentally or not) to end a call. I have an APP running in background that can track the incoming number of the phone at the moment that I receive a call and while doing the call.
As the "red button" to end a call is not a hardware button in the touch screen phones, I'm struggling trying to know how to detect when I pressed that button. And I'm starting to think that is not really possible.
I have searched and I found that there are ways to know the position that your fingers are touching in the screen while running your APP, (I don't know if this is possible when your APP is running in background) but as every android phone has a different shape and form of hanging up a phone call this is not a possible solution for my problem.
You can find out when the user hangs up a phone by implementing a BroadCast Receiver listening to phone state. When the state becomes Idle after either ringing state or offhook state, you can get to know the call has ended. If you just want to know when the call ends this method would work fine.
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.
i'm making a program that disables your wifi when you lock your screen
but i can't find an object the holds that kind of information (wether it's locked or not)
In most Android phones Wifi is turned off a few minutes after the screen is locked.
This setting can also be controlled by the user in Settings->Wireless Netowrks->WiFi->Advanced.
Anyway, if you want to tell when the screen is locked, register to receive the ACTION_SCREEN_OFF broadcast intent.