I wrote a little widget for Android devices.
The widget uses AlarmManager to set recurring updates.
I'm using the RTC clock for the AlarmManager.
According to the documentation, if the device is sleeping, the RTC clock won't wake up the device and the next update will be when the device is woken.
I have a log file for the widget which shows when it was updated.
Even when I don't touch the device , I still see updates in the log file.
Why is that? shouldn't the device be sleeping and thus my widget shouldn't update?
I'm using System.currentTimeMillis() for the starting time so it should be correct for RTC clock.
You need to disconnect device from your desktop. When device is charging it doesn't go to sleep mode even when screen is black.
Related
Basically I am trying to add an alarm feature to my app.
set time & date, save >> turn the app off >> when it's the time, RING-RING-!
But to do this, the app should wake itself to run the alarm feature; otherwise it won't work unless the app is running at the alarm time.
Any regular alarm apps just open itself when its the time, even when the app was not running on the phone. does anyone here know how apps self-wake?
Thanks very much
Use AlarmManager to do alarm envenif the app is not running.
But if the machine reboot, it will not work. So we need to run a service to register alarm when machine boot complete.
I program an application, which is connected to bluetooth device and used in a car (in the background) and navigation (or something else) in the foreground.
But on android 7+ (maybe also 6), application go to sleep after some time. When I'm trying to take picture from camera the "sleep mode" is immediately and my app is sleeping now (no bluetooth connection, no notifications) - just dead app.
I must go to recent apps -> click on my app and this make the "wake up". Bluetooth is now connecting to device again.
But I can't still check if the app is sleeping or not. So, how to keep app awake also in background?
I read some about WakeLock, but it looks like it's not working, cause app still sleeping. BUút maybe I'm using it wrong.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wk = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyWakeLock");
wk.acquire();
and onDestroy
wk.release();
Thanks
From Android API 23 onward, Google has introduced Doze mode and App Standby in order to conserve battery power. When a device enters doze mode or an app enters App Standby, all tasks done by an app is deferred. We had an issue with an Alarm which was not firing because of the same. If you read upon docs, you will find that using a Wake Lock is not gonna help either.
Doze restrictions The following restrictions apply to your apps while
in Doze:
Network access is suspended.
The system ignores wake locks.
Standard AlarmManager alarms (including setExact() and setWindow()) are
deferred to the next maintenance window. If you need to set alarms
that fire while in Doze, use setAndAllowWhileIdle() or
setExactAndAllowWhileIdle(). Alarms set with setAlarmClock() continue
to fire normally — the system exits Doze shortly before those alarms
fire.
The system does not perform Wi-Fi scans.
The system does not allow sync adapters to run. The system does not allow JobScheduler to run
So if you want to bypass all these, your app must have a process in the foreground. Once again from the same doc -
The app has a process currently in the foreground (either as an
activity or foreground service, or in use by another activity or
foreground service).
In your case run a service and raise it's priority to foreground.
for wakelock to work, u should add this line to your androidmanifest file at the beginning. but as Ajay said, u should use a service so that the service works in background and do the job but if you want to keep the screen on that's something else which i think it is not the case here.
<uses-permission android:name="android.permission.WAKE_LOCK" />
xml layout file under layout type:
android:keepScreenOn="true">
why don't you use service? WakeLock basically keeps the screen on which is not an efficient mechanism
https://developer.android.com/training/scheduling/wakelock.html
My app needs to wake the user up in the night so I would like to access the device's clock alarm and add my own in there. The alarm times shifts throughout the month, so I would need to access it and update it.
For example, I would like to add a daily alarm in the device clock alarm. Then everyday, I would like to run some calculation and adjust the time for the daily alarm.
Is this possible? I found AlarmManager but this seems like a scheduler not the device clock alarm. Perhaps there is an intent for the clock alarm? The screenshot below is the setting I am trying to access from my app (without rooting the device).
Here you have a tutorial about programming alarms for Android.
https://developer.android.com/training/scheduling/alarms.html
The thing is that is not needed to access the native clock app to set them, you can do it with your own app.
Be aware that this will not program an "Alarm"(with music and so on), it will only provide you the possibility to shcedule some task. In your case this task could be wake up the user with a loud music or whatever.
I m new to android world n m trying to make an app that wakes up my device from standy mode at a particular time.
I tried a few places where they mentioned about wakelock but this thing just prevents the device from going into standy mode.
I basically want my device to wake up from standby mode.
Like take the example of alarm clock... once set i can leave it and at that time from standby mode I get to see that the phone is active.
I even tried developer site for android... but it wasn't much helpful!
Any help would be highly appreciated!
You have to use Alarm Manager to schedule a repeated alarm (use RTC_WAKEUP for type parameter).
Then your code will execute even if the device is sleep. but notice that the registered alarm will removed once the device is restarted so you have a re-schedule the alarm again (by listening to boot broadcast)
While developing an iphone and android application using phonegap,came to a point where i have to build a alarm clock functionality like the image.
I am setting the alarm using Jquery which is running properly when user is in app. But it's not working when the app is closed or the phone is in sleep mode.
Is there any way to proceed?
I'm not sure if there is a phonegap equivalant, but in Android you'll need to use the AlarmManager for the alarms. This will launch your application when the alarm is triggered. You'll also need to set a WakeLock when you have active alarms. Otherwise the device can go into sleep mode and you won't get the alarms:
http://developer.android.com/reference/android/os/PowerManager.html
The Android Alarm uses the PARTIAL_WAKE_LOCK and only when there are active alarms.