I am trying to put my emulators into sleep mode to test some behavior.
For this, I deactivate the charger, set the battery to "uncharging" and a low battery %. Then I lock the screen over the power button (swipe to unlock is activated).
Then I start some background operation (for example an IntentService) without holding a wake lock and leave the app, but everything just keeps running as if the screen was on.
The emulator seems to not fall into sleep.
Not a duplicate since I am already following these exact steps (as described above)
Related
This is a general question about how to ensure that GCM push notifications wake up the device (i.e. unlock the screen, and turn the screen on) so that we can render a custom view and make the phone vibrate and ring. We have been using GCM notifications this way successfully in our application, but after a certain period of time (~10 minutes), the phone will no longer respond to the notifications. After this 10 minute threshold, the user needs to manually unlock their device to in order to initiate the expected behavior (starting an activity that renders a custom view, turns on the ringtone, and vibrates).
We tried turning off battery optimizations on the device and starting a foreground service that implements a partial wake lock. In addition, we have tried using FLAG_SHOW_WHEN_LOCKED, FLAG_KEEP_SCREEN_ON, and FLAG_TURN_SCREEN_ON to make sure the app can bypass the lock screen. All of those efforts have not enabled us to wake up the device after it appears to go into a deep sleep mode at about 10 minutes of idle time.
Can you please inform me of how to circumvent this limit in how long the phone can respond to notifications? The issue appears to be Android version and device/manufacturer agnostic. We have tested on Pixel XL, Pixel 3 XL, Samsung Galaxy S9, Samsung Galaxy S8, and various other devices, all with similar results.
It seems like after a certain point of sleep/idle/locked time, the phone can no longer respond to notifications that attempt to wake up the device, unlock the screen, and turn the screen on. Is there a way around this?
the last couple of days i was busy getting a service up and running for an phone gap application (using the eclipse ide with the device (motorola defy android 2.3.) connected to my computer)/ the service runs in the background when the application is off and has a timer scheduled that passes an intent to launch my application at irregular times/ everything is working as intended/ when the application is off and the device sleeps (screen is black) the timer is still running and at the scheduled time the device gets woken up, the lock removed and the app starts/ however, the bummer came when i unplugged my device from my computer/ the timer seems to work only reliable in sleepmode when the device is connected to my computer/ when its not connected to my computer the timer only fires correctly when the screen is on/ when it is not on it fires unpredictable at will and more often not at all/ i switched off the option that the device should not go in deep sleep when charging/ but it still works when the device is either connected to a power outlet or computer
can anyone try to explain what the reason might be?
is there anything i can do to make sure the timer is running as is should unplugged while the device is sleeping
Sorry my bad, it doesn't FULLY answer your question
One way is to register for ACTION_SCREEN_OFF and ACTION_SCREEN_ON event at the native level and propagate that event to phonegap layer (# html/js level).
More details on handling Screen Off and On intent click here.
More on how to Notify UI layer click here.
i have coded my 2nd android application that switches audio profiles based on a certain schedule (date and time only as of now)....the code is working without any issues if i run the code using the emulator via eclipse...however i recently exported the apk and installed it on my At&t Samsung Galaxy S2 and added the same profile schedule as the emulator, but for some odd reason the timertask is not executing after the 1st time...
For Example:
Here is the Profile Schedule from my phone as well as the emulator:
8AM - 5:30PM -- Work
5:30PM - 10PM -- Home
10PM - 8AM -- Sleep
once the above is scheduled and i press the activate button on the main activity..a background service runs switching from one profile to the next until it is de-activated...
the only difference i have noticed between the emulator and my phone is that, the emulator screen never shuts off...so im guessing that the emulator doesnt ever go on sleep? whereas, my phone's screen turns off after about 30 seconds of inactivity, in addition to the lock screen...furthermore, i turned on USB debugging on the phone and plugged it directly into the computer and from what it seemed like, the code was executing, switching one profile to the next, on my phone without any issues...(Note that, when i was doing this testing, i used smaller time intervals in the profile schedules)...Additional details: i have also added startForeground() in my service code and ensured that the service is not getting terminated...
does anyone have any idea on what im missing, or what i can do to get around this bizarre problem?...i did do some research before posting this, and found out few posts that recommended using: Android's PowerManager...
Thanks for your input
Nothing weird about this: if the phone is asleep, the CPU is off and you cannot execute code. Don't use TimerTask on Android, use AlarmManager to schedule recurring tasks. It's implemented in the kernel and can wake up the phone if necessary (that might have a negative impact on battery life, so use with caution). Also look into WakeLock's.
http://developer.android.com/reference/android/app/AlarmManager.html
I'm developing an app which requires the system to get the touch events even after the system goes to sleep mode or after the user locks the screen, I tried searching for a solution but it is hard to find one.
Should I want to set any permissions or is there any inbuilt methods or can I override any methods to perform this functionality.
I'm developing an app which requires the system to get the touch events even after the system goes to sleep mode or after the user locks the screen
Fortunately, this is not possible. Otherwise, the device would not be asleep, and battery life would suffer as a result.
Here is a link that shows how to prevent the phone from sleeping.
If you couple that with, say a black screen to 'pretend' the hone is sleeping but actually running your code. So your code can still intercept touch event
Then you need to install your app as a service and make it start when the device is turned on.
You will not need NDK or rooted device for that (sorry, got a short night :) )
I have made an app that starts a service, which starts a timer, which fires off a small function after an amount of time. This is working great on the emulator and on the Motorola Droid 1, but it doesn't work on the Droid X when the phone has been put into sleep mode. What I have discovered is that the timer seems to pause when the phone is in sleep. It doesn't seem to do this on the Droid 1, or the emulator. I'm sure the workaround isn't too difficult, so I'm not asking for help(for once) I just want an explanation, to better understand this.
My question is what exactly does "sleep mode" do on android systems? What does it stop, what doesn't it stop, etc. By sleep mode I mean, of course, when you press the power button and the screen goes black. What exactly is happening? Any insight is appreciated.
I'm sure the workaround isn't too difficult
Using AlarmManager is a bit tricky.
My question is what exactly does "sleep mode" do on android systems?
Primarily, it shuts down the CPU. Along the way, non-essential radios (WiFi, GPS) will have been shut down as well.
What does it stop, what doesn't it stop, etc.
About the only thing you can count on not stopping is the GSM or CDMA radio (for incoming calls, SMSes, and IP packets) and AlarmManager.
By sleep mode I mean, of course, when you press the power button and the screen goes black.
Actually, that's not sleep mode, per se. That is the screen turning off.
The device will go into sleep mode shortly thereafter, if nothing is keeping it awake with a WakeLock. However, there is no guarantee that within a millisecond of you pressing that button and the screen turning off that the CPU is off.