I want to start an activity if the clock is 15.00. Is there any reference ?
Assuming i had running services in my background.
EDIT
I have value from database. Then the activity will trigger based on clock that i saved from database. So if the database has values like 01.00 , 13.00 , 22.30 then the activity will start when the phone clock match as that 3 value.
You can use an AlarmManager for that
This post will help you. Use AlarmManager to set a repeating alarm. The time can be set.
Android notification app not working properly
Related
I am working on one android application which allows user to set reminder for specific task or work. and i have created reminder in android using alarm manager. But my problem is when user move to some other time zone how can i change reminder time as per new time zone ?
2nd problem is if user have set reminder for two task at same time which one will get canceled by system ?
As android doesn't provide id for reminder.
I have already checked link1, link2 questions on SO but it is not valid for me in my 2nd case.
You should not to do that becouse you set it up in abcolute unix time value right?
It means that the same absolute time event will happens in the same moment in every time zone
P.S to cancele alarm you should use the same Intent as you use whent setup alarm. It just override previous alarm by new one. In my application i use only one alarm for all events, and i invalidate it value every time and set it up to earliest event time
I have a fragment with a button that starts a BroadcastReceiver. This BroadcastReciever creates a notification after a time retrieved from the fragment. This part works.
However, when I press the button more than once, the existing broadcast receiver is overwritten. I don't want this as I want multiple notifications to be created.
Any solutions?
Thank you
I found the answer - The pending intent used in the alarm manager was not unique so it was overwritten each time I created another alarm. What I needed to do was create multiple alarms. This is done by adding a unique id to the 2nd parameter (argument?) of the pending intent.
See this answer for more details: https://stackoverflow.com/a/10090378/2442638
I have an array of specified hours for each day, when brightness should by changed for application which is awake 24/7. It happens twice a day.
What I want to achieve is to find the most economical way of implementation that problem.
Should I use AlarmManager or maybe there is a better sollution?
Activity is always awake...
If your app doesn't show any UI while it's awake, use the AlarmManager.
Finally, I decided to use an AlarmManager with BroadcastReceiver setting value in SharedPreferences and then in Activity I have a Handler which checks that value.
I am trying to cancel an alarm that was set last time my app was run. This alarm has a PendingIntent that was set with PendingIntent.getBroadcast and an inner Intent that contains some variables set by intent.putExtra. My question is this, I know that alarms can be canceled by calling alarmManager.cancel(pendingIntent) where pendingIntent is the same as the one used to set the alarm. But, if the variables placed into the intent are changed will the alarm still be canceled? For example, I set an alarm with intent.putExtra("Joe") where Joe is a contact name. Later my app is closed and when it is re-run I try and cancel the alarm for "Joe" but the user has changed the name of the contact to "Jones". Can I cancel the alarm without knowing the variables I put into the intent?
Thanks!
I think it should cancel the alaram anyway, even though some data is different. The cancel method says:
Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.
And filterEquals says:
Determine if two intents are the same for the purposes of intent resolution (filtering). That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.
Anyhow, I'd still test it myself.
According to this question (which references the documentation), anything you add using putExtra is not taken into account when checking if an intent is equal to another one.
It shouldn't matter if the extra data is changed.
I am scheduling multiple intents to be send to a BroadcastReceiver.
The difference between every intent is the time when it will be received and extra data it contains.
Now I need to allow user to cancel specific alarms. According to AlarmManager.cancel() javadoc, it compares intents using filterEquals method:
http://developer.android.com/reference/android/content/Intent.html#filterEquals(android.content.Intent)
Now the problem is that according to filterEquals, all my intents are the same. Method checks against "action, data, type, class, and categories".
And unique data is either in intent extra bundle or as a time in AlarmManager.
I tried changing any of these parameters - for example using:
intent.setData(Uri.withAppendedPath(Uri.EMPTY, "some_unique_data"));
That would make every intent unique according to filterEquals method, but after changing Data to something like this, my intent does not reach BroadcastReceiver anymore.
What specific bit of data can I change to make every intent unique according to filterEquals and still receivable to my simple BroadcastReceiver?
Maybe I can modify my receiver in any way?
Ok, so I figured it out. As my every alarm has unique time and object ID, this is how I create my PendingIntent:
return PendingIntent.getBroadcast(context, time*100000+o.getId(), toFire, 0);
Now time is either 24 or 15 (24 hours before or 15 minutes before event I fire my alarm) and alarm data object contains unique ID. So I add both and specify it as a "requestCode" parameter in getBroadcast. That is enough to make unique intents based on same data.
Hope this helps anyone who has the same problem!
I ran across a similar problem for my app.
In my app, I used the SQLite DB to store details about each alarm, along with a unique ROW_ID.
So in my alarm listview, each row had a corresponding ROW_ID associated with it.
If the user clicks on a particular row, I just pass this ROW_ID to the method that performs the delete operation
Now, all my alarms were created with Intents which had their data part set as:
Uri.parse(Constants.INTENT_PRE + ROW_ID);
so in order to delete them, I create an Intent that has same data (as above, along with the unique ROW_ID) that was used while creating it.
Needless to say, from "action, data, type, class, and categories", only the "data" part is different for each of my existing PendingIntents.
Hope this helps!