Skip to content

Commit d46434f

Browse files
authored
Set the ForegroundServiceType for TransferService (#3620)
1 parent 9c9d69b commit d46434f

File tree

1 file changed

+8
-2
lines changed
  • aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility

1 file changed

+8
-2
lines changed

aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility/TransferService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.content.Intent;
2121
import android.content.IntentFilter;
2222
import android.content.pm.ApplicationInfo;
23+
import android.content.pm.ServiceInfo;
2324
import android.net.ConnectivityManager;
2425
import android.os.Build;
2526
import android.os.IBinder;
@@ -144,13 +145,18 @@ public int onStartCommand(Intent intent, int flags, int startId) {
144145
if (userProvidedNotification != null) {
145146
// Get the notification Id from the intent, if it's null, the default notification Id will be returned.
146147
ongoingNotificationId = (int) intent.getIntExtra(INTENT_KEY_NOTIFICATION_ID, ongoingNotificationId);
147-
148+
148149
// Get removeNotification from the intent, if it's null, removeNotification will be returned.
149150
removeNotification = (boolean) intent.getBooleanExtra(INTENT_KEY_REMOVE_NOTIFICATION, removeNotification);
150151

151152
// Put the service in foreground state
152153
LOGGER.info("Putting the service in Foreground state.");
153-
startForeground(ongoingNotificationId, userProvidedNotification);
154+
if (Build.VERSION.SDK_INT >= 34 /* UPSIDE_DOWN_CAKE */) {
155+
// We must provide a service type flag when application is targeting sdk >= 34
156+
startForeground(ongoingNotificationId, userProvidedNotification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
157+
} else {
158+
startForeground(ongoingNotificationId, userProvidedNotification);
159+
}
154160
} else {
155161
LOGGER.error("No notification is passed in the intent. "
156162
+ "Unable to transition to foreground.");

0 commit comments

Comments
 (0)