From ec63b15dc70837913bed91ceeccc12d8b4b24aad Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 6 Oct 2022 09:59:36 +0200 Subject: [PATCH] Fix sending media --- .../fedilab/android/jobs/ComposeWorker.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/src/main/java/app/fedilab/android/jobs/ComposeWorker.java b/app/src/main/java/app/fedilab/android/jobs/ComposeWorker.java index 532565d12..783fe47a1 100644 --- a/app/src/main/java/app/fedilab/android/jobs/ComposeWorker.java +++ b/app/src/main/java/app/fedilab/android/jobs/ComposeWorker.java @@ -39,6 +39,8 @@ import androidx.work.WorkManager; import androidx.work.Worker; import androidx.work.WorkerParameters; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import com.google.gson.Gson; import java.io.IOException; @@ -359,6 +361,7 @@ public class ComposeWorker extends Worker { } } + @NonNull @Override public Result doWork() { @@ -397,6 +400,29 @@ public class ComposeWorker extends Worker { return Result.success(); } + + @NonNull + @Override + public ListenableFuture getForegroundInfoAsync() { + // Build a notification using bytesRead and contentLength + Context context = getApplicationContext(); + // This PendingIntent can be used to cancel the worker + PendingIntent intent = WorkManager.getInstance(context) + .createCancelPendingIntent(getId()); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + createChannel(); + } + notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID); + notificationBuilder.setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher_foreground)) + .setContentTitle(context.getString(R.string.post_message)) + .setOngoing(true) + .setDefaults(NotificationCompat.DEFAULT_ALL) + .setPriority(Notification.PRIORITY_DEFAULT); + return Futures.immediateFuture(new ForegroundInfo(NOTIFICATION_INT_CHANNEL_ID, notificationBuilder.build())); + } + @NonNull private ForegroundInfo createForegroundInfo() { // Build a notification using bytesRead and contentLength