1414import androidx .annotation .IntegerRes ;
1515import androidx .annotation .RequiresApi ;
1616import androidx .core .app .NotificationCompat ;
17+ import androidx .work .ForegroundInfo ;
1718import androidx .work .WorkInfo ;
1819import androidx .work .WorkManager ;
20+ import android .content .pm .ServiceInfo ;
1921
2022import java .util .Collections ;
2123import java .util .List ;
@@ -82,7 +84,7 @@ public static Notification createNotification(NotificationCompat.Builder notific
8284 Notification notification = notificationBuilder .build ();
8385 notification .flags |= Notification .FLAG_NO_CLEAR ;
8486 notification .flags |= Notification .FLAG_ONGOING_EVENT ;
85- return notification ;
87+ return notification ;
8688 }
8789
8890 @ RequiresApi (api = Build .VERSION_CODES .O )
@@ -103,7 +105,9 @@ private static NotificationCompat.Builder getUploadNotification(final Context co
103105 PendingIntent pendingIntent = PendingIntent .getActivity (context , 0 , notificationIntent , pendingIntentFlag );
104106
105107 // TODO: click intent open app
106- @ SuppressLint ("ResourceType" ) NotificationCompat .Builder uploadNotificationBuilder = new NotificationCompat .Builder (context , UploadTask .NOTIFICATION_CHANNEL_ID )
108+ @ SuppressLint ("ResourceType" )
109+ NotificationCompat .Builder uploadNotificationBuilder = new NotificationCompat .Builder (context ,
110+ UploadTask .NOTIFICATION_CHANNEL_ID )
107111 .setContentTitle (notificationTitle )
108112 .setTicker (notificationTitle )
109113 .setSmallIcon (notificationIconRes )
@@ -117,4 +121,13 @@ private static NotificationCompat.Builder getUploadNotification(final Context co
117121
118122 return uploadNotificationBuilder ;
119123 }
124+
125+ public ForegroundInfo getForegroundInfo () {
126+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
127+ return new ForegroundInfo (notificationId , notificationBuilder .build (),
128+ ServiceInfo .FOREGROUND_SERVICE_TYPE_DATA_SYNC );
129+ } else {
130+ return new ForegroundInfo (notificationId , notificationBuilder .build ());
131+ }
132+ }
120133}
0 commit comments