Skip to content

Commit

Permalink
LocationService.java: Fix #3 for SecurityException crash on Android 14
Browse files Browse the repository at this point in the history
  • Loading branch information
eladnava committed Sep 4, 2024
1 parent be0ffa3 commit 0cd0392
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ public class LocationService extends Service implements
public void onCreate() {
super.onCreate();

// Start foreground service
// API level 34 support
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(PushyForegroundService.FOREGROUND_NOTIFICATION_ID, getForegroundNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
} else {
startForeground(PushyForegroundService.FOREGROUND_NOTIFICATION_ID, getForegroundNotification());
}

// Must have Google Play Services
if (!GooglePlayServices.isAvailable(this)) {
stopSelf();
Expand All @@ -86,6 +78,14 @@ public void onCreate() {
return;
}

// Start foreground service
// API level 34 support
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(PushyForegroundService.FOREGROUND_NOTIFICATION_ID, getForegroundNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
} else {
startForeground(PushyForegroundService.FOREGROUND_NOTIFICATION_ID, getForegroundNotification());
}

// Initialize location polling
initializeLocationPolling();

Expand Down Expand Up @@ -154,6 +154,13 @@ void connectLocationClient() {

@Override
public int onStartCommand(Intent Intent, int Flags, int StartId) {
// Check if the user revoked location permission
// Must have location permission to continue
if (!LocationLogic.isLocationAccessGranted(this)) {
stopSelf();
return START_NOT_STICKY;
}

// Start foreground service
// API level 34 support
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
Expand Down

0 comments on commit 0cd0392

Please sign in to comment.