|
20 | 20 | import android.content.Intent;
|
21 | 21 | import android.content.IntentFilter;
|
22 | 22 | import android.content.pm.ApplicationInfo;
|
| 23 | +import android.content.pm.ServiceInfo; |
23 | 24 | import android.net.ConnectivityManager;
|
24 | 25 | import android.os.Build;
|
25 | 26 | import android.os.IBinder;
|
@@ -144,13 +145,18 @@ public int onStartCommand(Intent intent, int flags, int startId) {
|
144 | 145 | if (userProvidedNotification != null) {
|
145 | 146 | // Get the notification Id from the intent, if it's null, the default notification Id will be returned.
|
146 | 147 | ongoingNotificationId = (int) intent.getIntExtra(INTENT_KEY_NOTIFICATION_ID, ongoingNotificationId);
|
147 |
| - |
| 148 | + |
148 | 149 | // Get removeNotification from the intent, if it's null, removeNotification will be returned.
|
149 | 150 | removeNotification = (boolean) intent.getBooleanExtra(INTENT_KEY_REMOVE_NOTIFICATION, removeNotification);
|
150 | 151 |
|
151 | 152 | // Put the service in foreground state
|
152 | 153 | 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 | + } |
154 | 160 | } else {
|
155 | 161 | LOGGER.error("No notification is passed in the intent. "
|
156 | 162 | + "Unable to transition to foreground.");
|
|
0 commit comments