Write isForeground() method
This commit is contained in:
parent
3de8074511
commit
f88de024b8
@ -45,10 +45,18 @@ public abstract class ChronometerNotificationService extends Service {
|
|||||||
protected abstract boolean isCountDown();
|
protected abstract boolean isCountDown();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the id for the foreground notification
|
* @return the id for the foreground notification, if {@link #isForeground()} returns true.
|
||||||
|
* Otherwise, this value will not be considered for anything.
|
||||||
*/
|
*/
|
||||||
protected abstract int getNoteId();
|
protected abstract int getNoteId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether this service should run in the foreground. The default is true.
|
||||||
|
*/
|
||||||
|
protected boolean isForeground() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The intent received in {@link #onStartCommand(Intent, int, int)}
|
* The intent received in {@link #onStartCommand(Intent, int, int)}
|
||||||
* has no {@link Intent#getAction() action} set. At this point, you
|
* has no {@link Intent#getAction() action} set. At this point, you
|
||||||
@ -80,7 +88,9 @@ public abstract class ChronometerNotificationService extends Service {
|
|||||||
.setShowWhen(false)
|
.setShowWhen(false)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setContentIntent(getContentIntent());
|
.setContentIntent(getContentIntent());
|
||||||
|
if (isForeground()) {
|
||||||
startForeground(getNoteId(), mNoteBuilder.build());
|
startForeground(getNoteId(), mNoteBuilder.build());
|
||||||
|
}
|
||||||
mDelegate.init();
|
mDelegate.init();
|
||||||
mDelegate.setCountDown(isCountDown());
|
mDelegate.setCountDown(isCountDown());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user