do not crash on calling startForeground() with missing FOREGROUND_SERVICE permission

This commit is contained in:
B. Petersen
2019-10-11 23:18:56 +02:00
parent 2a8ccbd99c
commit 6af9bf407d
@@ -56,7 +56,15 @@ public class KeepAliveService extends Service {
// there's nothing more to do here as all initialisation stuff is already done in
// ApplicationLoader.onCreate() which is called before this broadcast is sended.
s_this = this;
setSelfAsForeground();
// set self as foreground
try {
stopForeground(true);
startForeground(FG_NOTIFICATION_ID, createNotification());
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
@@ -78,11 +86,6 @@ public class KeepAliveService extends Service {
// the service will be restarted due to START_STICKY automatically, there's nothing more to do.
}
private void setSelfAsForeground() {
stopForeground(true);
startForeground(FG_NOTIFICATION_ID, createNotification());
}
static public KeepAliveService getInstance()
{
return s_this; // may be null