I am a beginner
i want to Give Notification on specific day in long time example i want to set Notification for 6 months longer Should I use ŮŽAlarm Manager or countdown timer , Or I can do it by Conditions and joda-time Component?
timer is not a good idea because it may kill by os but you can use the alarmManager or workManager but you should also listing on device boot complete and register your task again to alarmManager
here is a good tutorial for using alarm manager :
https://en.proft.me/2017/05/7/scheduling-operations-alarmmanager-android/
Related
Backgroud
I am using AlarmManager and JobScheduler(=> API 21) to generate Notification at 11 am in the morning.
Issue
Suppose my device is turned off at 11 am. So Alarm will not go off and Notification is not generated for today. Now, when it will reboot. the alarm is set again for 11 am of next day using BroadCastReceiver on action.BOOT_COMPLETED.
I have explored Job Scheduler a bit and setPeriodic(ms) function is used to set a periodic job but does not allow to schedule a job at specific time.
(Google -> define schedule -> arrange or plan (an event) to take place at a particular time.).
Any pointer to workarounds to this use case. I would prefer native solution, though.
What is the best way to implement repeating alarm in my android application? Every user selects a specific time and I want to notify them when this time approaches on daily bases. I have come across this, but I am wondering whether this is the best way?
The alarm manager should meet your needs. There is no better way except for maybe having a server ping your client.
Since android really doesn't like things that repeat on a predictable interval, and since recent versions don't let you repeat on an exact fixed interval anyway, you'll need to schedule the alarm at the time you want, and then when that alarm fires, schedule a new one for the next day at the time you want.
use
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarm_time,
intervel, pendingIntent);
in your activity
I'm learning Android and want to write some kind of count-down timer application, so I get a ring-tone after certain minutes are elapsed. The timer also should work if the user has closed the application or switched to another one. If my application is running, it should be able to display the remaining time.
I've tried with CountDownTimer, but this seems only to work when the phone is activated, but not like the alarms which could ring you up at the morning. What other similar API alternatives are there to activate the device if the time is elapsed?
You can use AlarmManager for this purpose.
count-down and alarm are two very different things (even thou both count time).
Count-down you probably want to run a service and put a notification with the flag ongoing = true updating the value of the time.
Alarm you want to use the AlarmManager (as pointed out by #PgmFreek) that you can schedule a specific time that the system will call an Intent for you.
Hi I need to set AlarmManager to run a reminder for me to take medication. I need to repeat it by custom amount of days and custom amount of times to take in the day.
So is there an efficient way to set the AlarmManager or CommonsWare's Implementation of the AlarmManager to remind me "twice a day starting at 9AM for the next 5 days" to remind me to take medication? Pls advice and tnx in advance for any constructive help in sample code and in relevant tutorials.
I haven't looked into Mark's AlarmManager implementation, but there is no way, in general, to get the bare AlarmManager to do what you are trying to do. You can schedule a single alarm, at a specific time, or a repeating alarm, that repeats at fixed intervals. If you want something that handles complex schedules like the one you describe, you'll have to write or find code that does it.
You want to use a PendingIntent with the AlarmManager. The idea is to schedule the pendingIntent with the alarmManager, have that trigger an intentService or broadcast, setup another pendingIntent with the alarmManager for the next desired event. You want to keep in mind that you'll need the BOOT_RECEIVED permission in case the user reboots their device. I have complex scheduling in Audio Control and this is exactly what I do.
Here is a pretty decent tutorial of what I mean:
http://android-er.blogspot.com/2010/10/simple-example-of-alarm-service-using.html
You need to schedule an alarm to the next time you want to take the medicine - according to your algorithm (for example if its twice a day, and you got to the pending intent callback for the first time today, then schedule the next alarm to start after [6,7,8,9,10...] hours).
You will need to save both last time of the alarm launch and the user settings in shared prefs/file/DB.
You need to handle process down (android killed it or the device was rebooted). In the case of device reboot you should use the boot receiver to start your service, but you need to remember that from android 3.1 the user has to use at least one time the GUI in order for you to intercept the boot completed receiver. The boot completed receiver should look when was the last time that the alarm launched, and according to the user settings set the next alarm launch.
In the case of android killed your service, you will need to make research, i can't help here.
see example
I want my app to start automatically every month on a particular day(Specified by user).
I searched a lot on Google, but I din get any solution. I got alarm for seconds like the app starts after a particular seconds. I am new to android. So an example will be highly appreciated
You are looking for the AlarmManager class.
Quoting from the documentation,
This class provides access to the system alarm services. These allow
you to schedule your application to be run at some point in the
future.
create a service with alarm manager ...........
and start the app when particular date comes