Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
6
600SeriesAndroidUploader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cgm
uploader
600SeriesAndroidUploader
Commits
7181177c
Commit
7181177c
authored
8 years ago
by
Lennart Goedhart
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #83 from volkerrichert/master
minor improvements to alarm receiver
parents
7e3e65e0
301cb634
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/info/nightscout/android/medtronic/service/MedtronicCnlAlarmReceiver.java
+17
-10
17 additions, 10 deletions
.../android/medtronic/service/MedtronicCnlAlarmReceiver.java
with
17 additions
and
10 deletions
app/src/main/java/info/nightscout/android/medtronic/service/MedtronicCnlAlarmReceiver.java
+
17
−
10
View file @
7181177c
...
@@ -29,36 +29,43 @@ public class MedtronicCnlAlarmReceiver extends WakefulBroadcastReceiver {
...
@@ -29,36 +29,43 @@ public class MedtronicCnlAlarmReceiver extends WakefulBroadcastReceiver {
}
}
public
void
setContext
(
Context
context
)
{
public
void
setContext
(
Context
context
)
{
if
(
am
!=
null
&&
pi
!=
null
)
{
cancelAlarm
();
// here is an old alarm. So we cancel it before
cancelAlarm
();
}
am
=
(
AlarmManager
)
context
.
getSystemService
(
Context
.
ALARM_SERVICE
);
am
=
(
AlarmManager
)
context
.
getSystemService
(
Context
.
ALARM_SERVICE
);
Intent
intent
=
new
Intent
(
context
,
MedtronicCnlAlarmReceiver
.
class
);
Intent
intent
=
new
Intent
(
context
,
MedtronicCnlAlarmReceiver
.
class
);
pi
=
PendingIntent
.
getBroadcast
(
context
,
ALARM_ID
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
pi
=
PendingIntent
.
getBroadcast
(
context
,
ALARM_ID
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
}
}
// Setting the alarm
to call onRecieve every _REFRESH_INTERVAL seconds
// Setting the alarm
in 15 seconds from now
public
void
setAlarm
()
{
public
void
setAlarm
()
{
setAlarm
(
System
.
currentTimeMillis
());
setAlarm
(
System
.
currentTimeMillis
());
}
}
// Setting the alarm to call onRecieve
// Setting the alarm to call onRecieve
public
void
setAlarm
(
long
millis
)
{
public
void
setAlarm
(
long
millis
)
{
try
{
if
(
am
==
null
||
pi
==
null
)
am
.
cancel
(
pi
);
return
;
}
catch
(
Exception
ignored
)
{}
Log
.
d
(
TAG
,
"AlarmManager set to fire at "
+
new
Date
(
millis
));
cancelAlarm
();
// don't trigger the past and at least 30 sec away
if
(
millis
<
System
.
currentTimeMillis
())
millis
=
System
.
currentTimeMillis
();
Log
.
d
(
TAG
,
"AlarmManager set to fire at "
+
new
Date
(
millis
));
am
.
setExact
(
AlarmManager
.
RTC_WAKEUP
,
millis
,
pi
);
am
.
setExact
(
AlarmManager
.
RTC_WAKEUP
,
millis
,
pi
);
}
}
// restarting the alarm after MedtronicCnlIntentService.POLL_PERIOD_MS from now
// restarting the alarm after MedtronicCnlIntentService.POLL_PERIOD_MS from now
public
void
restartAlarm
()
{
public
void
restartAlarm
()
{
setAlarm
(
System
.
currentTimeMillis
()
+
MedtronicCnlIntentService
.
POLL_PERIOD_MS
);
setAlarm
(
System
.
currentTimeMillis
()
+
MedtronicCnlIntentService
.
POLL_PERIOD_MS
+
MedtronicCnlIntentService
.
POLL_GRACE_PERIOD_MS
);
}
}
// Cancel the alarm.
// Cancel the alarm.
public
void
cancelAlarm
()
{
public
void
cancelAlarm
()
{
if
(
am
==
null
||
pi
==
null
)
return
;
am
.
cancel
(
pi
);
am
.
cancel
(
pi
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment