Skip to content

Fix Background Uploads on Android#286

Open
J4t-P wants to merge 4 commits into
masterfrom
fix-android-upload
Open

Fix Background Uploads on Android#286
J4t-P wants to merge 4 commits into
masterfrom
fix-android-upload

Conversation

@J4t-P
Copy link
Copy Markdown

@J4t-P J4t-P commented Dec 23, 2025

This PR fixes an issue where background uploads were being terminated by the OS when the app was killed on Android 12+ devices. The fix ensures the UploadTask is correctly promoted to a Foreground Service, allowing it to persist independently of the app process.

On Android 12+, WorkManager requires Expedited work requests to implement getForegroundInfo() so the system can display a notification if the task runs long. The plugin was missing this implementation, causing the system to deny the expedited execution or kill the worker when the app process died. Additionally, the worker was not explicitly calling setForegroundAsync for Android 12+, relying on default behavior which proved unreliable for app-kill scenarios.

Solution:
Implemented getForegroundInfo(): Overrode this method in UploadTask.java to return a valid ForegroundInfo object containing the upload notification.

@J4t-P J4t-P self-assigned this Dec 23, 2025
@J4t-P J4t-P changed the title Add ForegroundInfo support for upload notifications Fix Background Uploads on Android Dec 23, 2025
Comment thread src/android/UploadTask.java Outdated
Copy link
Copy Markdown
Collaborator

@parveshneedhoo parveshneedhoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on different devices (2 Pixels and 2 Samsung phones).
The behavior is inconsistent: sometimes the upload starts in the background, and sometimes it doesn’t

Should we check this further to understand why it’s not consistent?

@J4t-P J4t-P force-pushed the fix-android-upload branch from f4fdb54 to 3d774b3 Compare January 16, 2026 11:07
@J4t-P
Copy link
Copy Markdown
Author

J4t-P commented Jan 20, 2026

Tested on different devices (2 Pixels and 2 Samsung phones). The behavior is inconsistent: sometimes the upload starts in the background, and sometimes it doesn’t

Should we check this further to understand why it’s not consistent?

Samsung’s "Adaptive Battery" often restricts background tasks.
Go to Settings > Apps.
Select the app having issues (e.g., Google Photos, OneDrive).
Tap Battery.
Change the setting to Unrestricted.

or

Go to Settings > Battery and device care > Battery.
Tap Background usage limits.
Tap Never sleeping apps.
Tap the + icon and add the app you want to keep running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants