try to catch startup error
This commit is contained in:
parent
3305a5979d
commit
be6c184061
2 changed files with 26 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.general.persistentNotification
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
|
@ -32,7 +33,11 @@ class DummyService : DaggerService() {
|
|||
super.onCreate()
|
||||
// TODO: I guess this was moved here in order to adhere to the 5 seconds rule to call "startForeground" after a Service was called as Foreground service?
|
||||
// As onCreate() is not called every time a service is started, copied to onStartCommand().
|
||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||
try {
|
||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||
} catch (e: Exception) {
|
||||
startForeground(4711, Notification())
|
||||
}
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventAppExit::class.java)
|
||||
.observeOn(Schedulers.io())
|
||||
|
@ -52,7 +57,11 @@ class DummyService : DaggerService() {
|
|||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||
try {
|
||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||
} catch (e: Exception) {
|
||||
startForeground(4711, Notification())
|
||||
}
|
||||
return Service.START_STICKY
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.services
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Notification
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -73,17 +74,27 @@ class LocationService : DaggerService() {
|
|||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||
try {
|
||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||
} catch (e: Exception) {
|
||||
startForeground(4711, Notification())
|
||||
}
|
||||
return Service.START_STICKY
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||
try {
|
||||
startForeground(notificationHolder.notificationID, notificationHolder.notification)
|
||||
} catch (e: Exception) {
|
||||
startForeground(4711, Notification())
|
||||
}
|
||||
|
||||
// Get last location once until we get regular update
|
||||
LocationServices.getFusedLocationProviderClient(this).lastLocation.addOnSuccessListener {
|
||||
lastLocationDataContainer.lastLocation = it
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||
LocationServices.getFusedLocationProviderClient(this).lastLocation.addOnSuccessListener {
|
||||
lastLocationDataContainer.lastLocation = it
|
||||
}
|
||||
}
|
||||
|
||||
initializeLocationManager()
|
||||
|
|
Loading…
Reference in a new issue