Android Alarm Scheduling with repeats - java

I am in need of creating an app with "reminding" facility. For an example, user can set a reminder for "Jogging" and he can do following when setting up this reminder. Below is the normal process.
User setup the reminder with "cause" to be reminded (ex: jogging )
User can set the reminder to fire at 10am Monday, and so on.
If required, user can set the alarm for multiple days (ex: Monday, Tuesday, Friday )
user can set the reminders to be repeated. (Ex: "Every Monday at 10am". Ie else "Every Monday, Tuesday, Sunday at 10am ")
User can set any number of reminders for various causes.
At the time of reminder, the user will get a notification in his phone.
After setting the reminder, entire process will run in background.
I was trying to find a better way to do this, this is basically like an alarm application. I looked into 'AlarmManager' , 'JobScheduler' and so on, nothing seems to match what I want to do, the correct alarm set-up and repeated reminders when set.
I looked into some alarm app examples too, seems too complicated when my core app is not an "alarm" app.
What is the exact library of doing this? I am not creating an alarm app, this is a process required for another app we build.

Related

How to send a local repeating notification in certain days?

I have a reminders app, I made a UI that looks like this where the user can pick multiple days and the hour that he wants to be reminded on. For example, I can select Monday and Tuesday at 15:00 and I should be reminded those days at that given hour. But I canĀ“t figure out how to make this work (mainly, the mutiple days thing). Any ideas?
You can send a local repeating notification with the help of AlarmManager. setRepeating() function can be used to schedule notifications.
similar question, Check this link for better understanding.

Play Store Billing : Get last subscription renewal date

I am currently trying to fix the following edge case in my app, without using the "Google Play Android Developer API" :
User buys Subscription(e.g. 1st of January)
Several Subscription renewals occur
User cancels his subscription(e.g. on the 15th of March)
User still has access to the subscription content, until the next billing period (e.g the 1st of March)
I am having difficulties doing so because whenever I call the queryPurchases() on my BillingClient object I always get the same data for orderId (Google states that the order ID should change based on the renewal recurrance number link ) and purchaseTime stay the same, no matter if queryPurchases(SkuType.SUBS) is called while the subscription is active or canceled (same behaviour occurs if I call the queryPurchaseHistoryAsync(). I would love to solve this issue without having to mess with the "Google Play Android Developer API".Using it seems a bit overkill for something as simple as getting the date of the last successful subscription renewal or just how many successful renewals there were.

How to make notifications appear during the week and only at certain times?

I want that app user receive notifications for example Monday, Tuesday, Wednesday, Thursday and Friday at 10:45. How can I do that?
You should use AlarmManager. Initialize it in your start activity. Create BroadcastReciever to handle notifications. Change your Manifest file.
Here is example

Android Date: Determining Future Date From Today

I have an app that allows users to set reoccurring alarms. In a fragment, they're allowed to pick a time from a TimePicker and set switches for what day they want the alarm to occur i.e. Mon,Wed,Fri.
I'm saving the time from the TimePicker in milliseconds and the days they choose as a string in an Alarm object like below.
public class Alarm extends RealmObject{
#PrimaryKey
private int id;
private Long time;
private String title;
private String dayOfWeek;}
What I'm trying to determine is how I figure out the future dates based on the days they want to schedule. For example, if today is Monday and they want to schedule an alarm for Mon, Wed and Fri, I would save an alarm object with a time of today, another alarm object with a time of today + 2 days and lastly one with an alarm of + 4 days.
However, the issue is this changes based on what day today is. If today is Tuesday, then I'll need to schedule an alarm for + 1 day, +3 days and + 6 days. What's the easiest way to calculate this day offset?
If I understand your question correctly, I would consider adding user shared preference (http://developer.android.com/reference/android/content/SharedPreferences.html)
containing a string alarmDaysOfWeek="Mon,Wed,Fri" or whatever value is based on user input.
Then you'd implement a Service that checks current day of week against the alarmDaysOfWeek in user's SharedPreferences and alarms if it's a match.
Just a suggestion:-
Set an alarm for everyday and when an Alarm Occur(Service,BroadcastReceiver) then check it if you have to something today(as par user's selection) or just do nothing.
By above ways you wont need calculations for +1 or +2.
I was able resolve this by capturing what day the user selected and then setting the day of the week on the calendar object like newAlarm.setDayOfWeek(x.getDayOfWeek) and then setting the time of the alarm object based on that. This way of a user selected a time in the past i.e. if today were Tuesday and they set an alarm for Monday, it would actually set the calendar object time in the past. Then when the alarm was scheduled, it would immediately fire and I could reschedule it for +7 days or next Monday.

How to get current time on another city correctly?

I have managed to read the web service to get current time of any given city.
I could get 2 important values from web service, current time (String) and the offset.
Question is
How to set time of any given city correctly?
Option 1:
Read machine/local time
Calculate UTC/GMT time out of machine time
City time = UTC time +/- offset value
But then what happens when machine time is wrong? You will also got
wrong time right?
Option 2:
Read current city time in String (2012-11-24 19:30)
Parse this time value and set it into Calendar
We got correct City time
But how about the next minute? Of course requesting the web service every minute to get current time is not a good solution right? Is it possible to maintain this Calendar instance keep running automatically every minute once we set it?
NB : I'm developing Android clock widget here.
Thanks
Option 1 is far better, in my eyes. Most cell phones have amazingly accurate time as time synchronization is an integral part of GSM and CDMA. Beyond that, I would far prefer a clock to work offline than to require internet connectivity.
If you are worried about ensuring accuracy in the face of incorrect system time, consider placing a call to a web service to get the current time for verification.
This verification could be done in the background, but keep in mind that web services are not the best time sync providers. I would let anything with under 5 minute difference go as it could be due to your server being out of sync or the call taking too long.

Categories