There is a bug with quiet time in the (7.2.5) Android SDK that I believe still exists in the latest version (8.0.2) and I would like to verify that someone has it working properly.
The bug happens when the start and end times for quiet time extend into the next/previous day. ( Example: Start time - 10PM, End time - 8AM ). In this case, the Date objects returned by PushManager.getQuietTimeInterval() have dates set that cause all calls to PushMananger.isInQuietTime() to always return true.
Example: On Sept 5th, Quiet time start - Sept 4th @ 10PM, Quiet time end - Sept 6th @ 8AM.
I believe this bug is only partially fixed in 8.0.2. In this case, there are two QuietTime time intervals in which no alerts should occur.
Example: On Sept 5th,
QuietTime 1 interval: [ Quiet time 1 start - Sept 4th @10PM, Quiet time 1 end - Sept 5th @8AM ]
QuietTime 2 interval: [ Quiet time 2 start - Sept 5th @ 10PM, Quiet time 2 end - Sept 6th @ 8AM]
In 8.0.2, PushManager.isInQuietTime() will incorrectly return false during the QuietTime 1 interval from 12AM to 8AM.
Has anyone else had this problem or am I misunderstanding how to use Quiet Time?
To work around this bug, I wrote my own isInQuietTime() function which has been working properly.
private boolean isInQuietTime() {
if(!UAirship.shared().getPushManager().isQuietTimeEnabled()) {
return false;
} else {
Date[] quietTimeInterval = UAirship.shared().getPushManager().getQuietTimeInterval();
if(quietTimeInterval != null && quietTimeInterval.length > 1) {
Calendar now = Calendar.getInstance();
int nowDay = now.get(Calendar.DAY_OF_YEAR);
// Get QuietTime start time and set today's date
Calendar startCalTime = Calendar.getInstance();
startCalTime.setTime(quietTimeInterval[0]);
startCalTime.set(Calendar.DAY_OF_YEAR, nowDay);
// Get QuietTime end time and set today's date
Calendar endCalTime = Calendar.getInstance();
endCalTime.setTime(quietTimeInterval[1]);
endCalTime.set(Calendar.DAY_OF_YEAR, nowDay);
if(endCalTime.after(startCalTime)) {
// Start and End occur sequentially, check if Now is in that range
return now.after(startCalTime) && now.before(endCalTime);
} else {
// End occurs before Start, check if Now is NOT in that range
return now.after(startCalTime) || now.before(endCalTime);
}
}
}
return false;
}
Comments
11 comments