diff --git a/aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility/TransferService.java b/aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility/TransferService.java index 2807bf76d4..d7216b3275 100644 --- a/aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility/TransferService.java +++ b/aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility/TransferService.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; +import android.content.pm.ServiceInfo; import android.net.ConnectivityManager; import android.os.Build; import android.os.IBinder; @@ -144,13 +145,18 @@ public int onStartCommand(Intent intent, int flags, int startId) { if (userProvidedNotification != null) { // Get the notification Id from the intent, if it's null, the default notification Id will be returned. ongoingNotificationId = (int) intent.getIntExtra(INTENT_KEY_NOTIFICATION_ID, ongoingNotificationId); - + // Get removeNotification from the intent, if it's null, removeNotification will be returned. removeNotification = (boolean) intent.getBooleanExtra(INTENT_KEY_REMOVE_NOTIFICATION, removeNotification); // Put the service in foreground state LOGGER.info("Putting the service in Foreground state."); - startForeground(ongoingNotificationId, userProvidedNotification); + if (Build.VERSION.SDK_INT >= 34 /* UPSIDE_DOWN_CAKE */) { + // We must provide a service type flag when application is targeting sdk >= 34 + startForeground(ongoingNotificationId, userProvidedNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC); + } else { + startForeground(ongoingNotificationId, userProvidedNotification); + } } else { LOGGER.error("No notification is passed in the intent. " + "Unable to transition to foreground.");