mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Compare commits
1 Commits
v2025.10.0
...
test/2025.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1d85f19a1 |
@@ -3,6 +3,7 @@ package app.organicmaps.downloader;
|
|||||||
import static android.Manifest.permission.POST_NOTIFICATIONS;
|
import static android.Manifest.permission.POST_NOTIFICATIONS;
|
||||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
|
|
||||||
|
import android.app.ForegroundServiceStartNotAllowedException;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
@@ -42,10 +43,24 @@ public class DownloaderService extends Service implements MapManager.StorageCall
|
|||||||
|
|
||||||
var notification = mNotifier.buildProgressNotification();
|
var notification = mNotifier.buildProgressNotification();
|
||||||
Logger.i(TAG, "Starting Downloader Foreground Service");
|
Logger.i(TAG, "Starting Downloader Foreground Service");
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
try
|
||||||
ServiceCompat.startForeground(this, DownloaderNotifier.NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
|
{
|
||||||
else
|
int type = 0;
|
||||||
ServiceCompat.startForeground(this, DownloaderNotifier.NOTIFICATION_ID, notification, 0);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||||
|
type = ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC;
|
||||||
|
ServiceCompat.startForeground(this, DownloaderNotifier.NOTIFICATION_ID, notification, type);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
|
||||||
|
e instanceof ForegroundServiceStartNotAllowedException)
|
||||||
|
{
|
||||||
|
// App not in a valid state to start foreground service (e.g started from bg)
|
||||||
|
Logger.e(TAG, "Not in a valid state to start foreground service", e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Logger.e(TAG, "Failed to promote the service to foreground", e);
|
||||||
|
}
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package app.organicmaps.location;
|
package app.organicmaps.location;
|
||||||
|
|
||||||
|
import android.app.ForegroundServiceStartNotAllowedException;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
@@ -160,10 +161,25 @@ public class TrackRecordingService extends Service implements LocationListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.i(TAG, "Starting Track Recording Foreground service");
|
Logger.i(TAG, "Starting Track Recording Foreground service");
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
|
||||||
ServiceCompat.startForeground(this, TrackRecordingService.TRACK_REC_NOTIFICATION_ID, getNotificationBuilder(this).build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
|
try
|
||||||
else
|
{
|
||||||
ServiceCompat.startForeground(this, TrackRecordingService.TRACK_REC_NOTIFICATION_ID, getNotificationBuilder(this).build(), 0);
|
int type = 0;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||||
|
type = ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION;
|
||||||
|
ServiceCompat.startForeground(this, TrackRecordingService.TRACK_REC_NOTIFICATION_ID, getNotificationBuilder(this).build(), type);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
|
||||||
|
e instanceof ForegroundServiceStartNotAllowedException)
|
||||||
|
{
|
||||||
|
// App not in a valid state to start foreground service (e.g started from bg)
|
||||||
|
Logger.e(TAG, "Not in a valid state to start foreground service", e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Logger.e(TAG, "Failed to promote the service to foreground", e);
|
||||||
|
}
|
||||||
|
|
||||||
final LocationHelper locationHelper = LocationHelper.from(this);
|
final LocationHelper locationHelper = LocationHelper.from(this);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
|||||||
import static app.organicmaps.util.Constants.Vendor.XIAOMI;
|
import static app.organicmaps.util.Constants.Vendor.XIAOMI;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.ForegroundServiceStartNotAllowedException;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
@@ -226,10 +227,25 @@ public class NavigationService extends Service implements LocationListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.i(TAG, "Starting Navigation Foreground service");
|
Logger.i(TAG, "Starting Navigation Foreground service");
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
|
||||||
ServiceCompat.startForeground(this, NavigationService.NOTIFICATION_ID, getNotificationBuilder(this).build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
|
try
|
||||||
else
|
{
|
||||||
ServiceCompat.startForeground(this, NavigationService.NOTIFICATION_ID, getNotificationBuilder(this).build(), 0);
|
int type = 0;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||||
|
type = ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION;
|
||||||
|
ServiceCompat.startForeground(this, NavigationService.NOTIFICATION_ID, getNotificationBuilder(this).build(), type);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
|
||||||
|
e instanceof ForegroundServiceStartNotAllowedException)
|
||||||
|
{
|
||||||
|
// App not in a valid state to start foreground service (e.g started from bg)
|
||||||
|
Logger.e(TAG, "Not in a valid state to start foreground service", e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Logger.e(TAG, "Failed to promote the service to foreground", e);
|
||||||
|
}
|
||||||
|
|
||||||
final LocationHelper locationHelper = LocationHelper.from(this);
|
final LocationHelper locationHelper = LocationHelper.from(this);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user