55
55
@ SuppressLint ("MissingPermission" )
56
56
public class GpsLoggingService extends Service {
57
57
private static NotificationManager notificationManager ;
58
- private static int NOTIFICATION_ID = 8675309 ;
59
58
private final IBinder binder = new GpsLoggingBinder ();
60
59
AlarmManager nextPointAlarmManager ;
61
60
private NotificationCompat .Builder nfc ;
@@ -89,10 +88,10 @@ public IBinder onBind(Intent arg0) {
89
88
public void onCreate () {
90
89
try {
91
90
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
92
- startForeground (NOTIFICATION_ID , getNotification (), ServiceInfo .FOREGROUND_SERVICE_TYPE_LOCATION );
91
+ startForeground (NotificationChannelNames . GPSLOGGER_DEFAULT_NOTIFICATION_ID , getNotification (), ServiceInfo .FOREGROUND_SERVICE_TYPE_LOCATION );
93
92
}
94
93
else {
95
- startForeground (NOTIFICATION_ID , getNotification ());
94
+ startForeground (NotificationChannelNames . GPSLOGGER_DEFAULT_NOTIFICATION_ID , getNotification ());
96
95
}
97
96
} catch (Exception ex ) {
98
97
LOG .error ("Could not start GPSLoggingService in foreground. " , ex );
@@ -126,10 +125,10 @@ public int onStartCommand(Intent intent, int flags, int startId) {
126
125
super .onStartCommand (intent , flags , startId );
127
126
try {
128
127
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
129
- startForeground (NOTIFICATION_ID , getNotification (), ServiceInfo .FOREGROUND_SERVICE_TYPE_LOCATION );
128
+ startForeground (NotificationChannelNames . GPSLOGGER_DEFAULT_NOTIFICATION_ID , getNotification (), ServiceInfo .FOREGROUND_SERVICE_TYPE_LOCATION );
130
129
}
131
130
else {
132
- startForeground (NOTIFICATION_ID , getNotification ());
131
+ startForeground (NotificationChannelNames . GPSLOGGER_DEFAULT_NOTIFICATION_ID , getNotification ());
133
132
}
134
133
} catch (Exception ex ) {
135
134
LOG .error ("Could not start GPSLoggingService in foreground. " , ex );
@@ -179,8 +178,7 @@ private void handleIntent(Intent intent) {
179
178
180
179
if (!Systems .locationPermissionsGranted (this )){
181
180
LOG .error ("User has not granted permission to access location services. Will not continue!" );
182
- stopLogging ();
183
- stopSelf ();
181
+ Systems .showErrorNotification (this , getString (R .string .gpslogger_permissions_permanently_denied ));
184
182
return ;
185
183
}
186
184
@@ -398,10 +396,10 @@ protected void startLogging() {
398
396
399
397
try {
400
398
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
401
- startForeground (NOTIFICATION_ID , getNotification (), ServiceInfo .FOREGROUND_SERVICE_TYPE_LOCATION );
399
+ startForeground (NotificationChannelNames . GPSLOGGER_DEFAULT_NOTIFICATION_ID , getNotification (), ServiceInfo .FOREGROUND_SERVICE_TYPE_LOCATION );
402
400
}
403
401
else {
404
- startForeground (NOTIFICATION_ID , getNotification ());
402
+ startForeground (NotificationChannelNames . GPSLOGGER_DEFAULT_NOTIFICATION_ID , getNotification ());
405
403
}
406
404
} catch (Exception ex ) {
407
405
LOG .error ("Could not start GPSLoggingService in foreground. " , ex );
@@ -529,21 +527,7 @@ private Notification getNotification() {
529
527
530
528
if (nfc == null ) {
531
529
532
- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .O ) {
533
- NotificationManager manager = (NotificationManager ) getSystemService (Context .NOTIFICATION_SERVICE );
534
-
535
- NotificationChannel channel = new NotificationChannel ("gpslogger" , getString (R .string .app_name ), NotificationManager .IMPORTANCE_DEFAULT );
536
- channel .enableLights (false );
537
- channel .enableVibration (false );
538
- channel .setSound (null ,null );
539
- channel .setLockscreenVisibility (preferenceHelper .shouldHideNotificationFromLockScreen () ? Notification .VISIBILITY_PRIVATE : Notification .VISIBILITY_PUBLIC );
540
-
541
- channel .setShowBadge (true );
542
- manager .createNotificationChannel (channel );
543
-
544
- }
545
-
546
- nfc = new NotificationCompat .Builder (getApplicationContext (),"gpslogger" )
530
+ nfc = new NotificationCompat .Builder (getApplicationContext (), NotificationChannelNames .GPSLOGGER_DEFAULT )
547
531
.setSmallIcon (R .drawable .notification )
548
532
.setLargeIcon (BitmapFactory .decodeResource (getResources (), R .mipmap .gpsloggericon3 ))
549
533
.setPriority ( preferenceHelper .shouldHideNotificationFromStatusBar () ? NotificationCompat .PRIORITY_MIN : NotificationCompat .PRIORITY_LOW )
@@ -566,22 +550,20 @@ private Notification getNotification() {
566
550
}
567
551
}
568
552
569
-
570
-
571
553
nfc .setContentTitle (contentTitle );
572
554
nfc .setContentText (contentText );
573
555
nfc .setStyle (new NotificationCompat .BigTextStyle ().bigText (contentText ).setBigContentTitle (contentTitle ));
574
556
nfc .setWhen (notificationTime );
575
557
576
558
//notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
577
- //notificationManager.notify(NOTIFICATION_ID , nfc.build());
559
+ //notificationManager.notify(NotificationChannelNames.GPSLOGGER_DEFAULT_ID , nfc.build());
578
560
return nfc .build ();
579
561
}
580
562
581
563
private void showNotification (){
582
564
Notification notif = getNotification ();
583
565
notificationManager = (NotificationManager ) getSystemService (NOTIFICATION_SERVICE );
584
- notificationManager .notify (NOTIFICATION_ID , notif );
566
+ notificationManager .notify (NotificationChannelNames . GPSLOGGER_DEFAULT_NOTIFICATION_ID , notif );
585
567
}
586
568
587
569
@ SuppressWarnings ("ResourceType" )
0 commit comments