|
1 | 1 | package com.platypii.baseline;
|
2 | 2 |
|
| 3 | +import com.platypii.baseline.util.Exceptions; |
| 4 | + |
3 | 5 | import android.app.Notification;
|
4 | 6 | import android.app.Service;
|
5 | 7 | import android.content.Intent;
|
@@ -58,12 +60,20 @@ public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
|
58 | 60 | private void updateNotification() {
|
59 | 61 | if (logging || audible) {
|
60 | 62 | // Show notification
|
| 63 | + if (!Permissions.hasLocationPermissions(this)) { |
| 64 | + Log.w(TAG, "Cannot start foreground service without location permission"); |
| 65 | + return; |
| 66 | + } |
61 | 67 | Log.i(TAG, "Showing notification");
|
62 |
| - final Notification notification = Notifications.getNotification(this, logging, audible); |
63 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
64 |
| - startForeground(Notifications.notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); |
65 |
| - } else { |
66 |
| - startForeground(Notifications.notificationId, notification); |
| 68 | + try { |
| 69 | + final Notification notification = Notifications.getNotification(this, logging, audible); |
| 70 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
| 71 | + startForeground(Notifications.notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); |
| 72 | + } else { |
| 73 | + startForeground(Notifications.notificationId, notification); |
| 74 | + } |
| 75 | + } catch (Exception e) { |
| 76 | + Exceptions.report(e); |
67 | 77 | }
|
68 | 78 | } else {
|
69 | 79 | // Stop service
|
|
0 commit comments