Skip to content

Commit

Permalink
Set the ForegroundServiceType for TransferService (#3620)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcreaser authored Jul 29, 2024
1 parent 9c9d69b commit d46434f
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit d46434f

Please sign in to comment.