I develop an application which must manage the Alarm Clock in Android. I specifically need to do the following:
execute some code in my application when the user sets an alarm (also find out the time of the alarm at the moment of execution);
cancel an alarm when the user pushes a specific button in my application;
execute some code in my application when an alarm goes off.
I must mention that I am not interested in the CPU alarms, but the Alarm Clock application, which people use to wake up.
You can set an alarm using the intent described here.
However, you can not intercept the AlarmClock UI or ringing alarms as you seek to.
You might want to look into scheduling your own reminders, probably using AlarmManager with RTC_WAKEUP.
Related
Im trying to run a notification if a user has not opened an app in say 24 hours to encourage them to open it (Similar to duolingo style). Im using Java and I can set a periodic notification using workmanager but it runs while the app is open which is not what I want. I want the notification to run every 24 hours however if the user has opened the app this timer should reset, I've searched for this but can't find what I require exactly
I would recommend to use AlarmManager for your case. You can, for example, reschedule it in Application.onCreate() method to fire in 24 hours after user last launched an app. First you need to cancel previously scheduled alarm using cancel method, and then set a new alarm to fire in 24 hours using one of the set...() methods available in AlarmManager class.
I am developing a school application, some functions require creating notifications and alarm clocks for the following cases:
Option to add notifications or alarms to remember some school assignment, taking into account that the user can have multiple school assignments and create multiple alarms or notifications for each one
Activation of an alarm clock for each day of the week
Option to receive a notification a few minutes before starting each class
Currently I am storing the information of notifications and alarms in a database, I am using AlarmManager to schedule them and BroadcastReceiver to show them or reschedule them when restarting the device.
So far everything has worked fine but I don't want to start the production release because there is a high probability that users schedule a lot of notifications and alarms, I don't know if this could lead to problems such as not activated alarms or slowing down of the application, I don't want the user to have a bad experience with this feature
So my main questions are: Is there any limit or recommendation for the number of Alarms programmed by AlarmManager?, Is my approach correct?
Currently when adding the notification it is scheduled immediately with AlarmManager regardless of the date, but I have this other idea: Just store the notification information without scheduling it with AlarmManager until the day it should be triggered ... Would it be more convenient to create a only service with AlarmManager that runs, for example, every day at 03:00 am and to schedule notifications and alarms for the day?
I hope someone can help me, thank you very much
I have jobscheduler that sends notification trigged by starting alarm and get canceled by an ending alarm, I have question, if i remove application from recent app or i reboot phone will alarm will trigged on specified time? and what happens to job scheduler
Thanks in advance!
Yes, it will be triggered. Alarm manager are system based not app base as long as you have that app installed in your device (and obviously alarm is set) alarm will be triggered on that specific time.
My problem is: I need to start countdown timer in my app which will work independently my app is opened or closed ...or even if my smartphone is off.
I really wonder how does android standard clock app works. I mean how it counts time even when my phone is off? Could anybody help me with this? I will appreciate any answer!
Internal to an android device will be a clock which runs from the battery and potentially syncs with network time when it has signal.
You can use AlarmManager and PowerManager to get your code to run at specific times, even if the phone is turned off:
Sometimes, it may be necessary for your android app to complete a task
sometime in the future. In order to do this, you must schedule an
activity (can also be a service) to be run using Android’s
AlarmManager. This post will show: How to set up a receiver for the
scheduled event How to create an activity from this receiver Using the
AlarmManager and the created classes to successfully receive and
process a scheduled event
http://justcallmebrian.com/2010/04/27/using-alarmmanager-to-schedule-activities-on-android/
http://www.techrepublic.com/blog/software-engineer/use-androids-alarmmanager-to-schedule-an-event/
I want my app to access database every hour and read next record from the table then update desctop widget and send notification. I know that there is AlarmManager which I can use to register my Intents but they are deleted when the phone is turned off or rebooted.
Is there any other android class/service that I would update my application continuously even when I reboot my phone?
Thanks,
take a look at the demo applications provided with android sdk
http://developer.android.com/samples/RepeatingAlarm/index.html
the look at AlarmService_Service for the implementation of the service once the alarm has been triggered
put all of the background tasks you want to do in your app in Services which perform tasks in the background. In the service you should be able to define a timer that causes whatever updates you want to occur every x hours.
In the onCreate() of the widget, start the service. onCreate() is called every time that the widget comes to life (such as when the phone starts if it is on the home screen) and will therefore guarantee that the Service is always running.
Hope this was helpful.
Just for the sake of completness, I am linking here the official docs, where the issue of the rebooting is adressed.
http://developer.android.com/training/scheduling/alarms.html#boot