Skip to content

Maui Android support for WorkManager #4065

Answered by BerserkerDotNet
omxie asked this question in Q&A
Discussion options

You must be logged in to vote

I managed to make it work with <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.7.1.5" />
Here is a sample code:

    public void SyncData()
    {
        using var builder = new Constraints.Builder();
        builder.SetRequiredNetworkType(NetworkType.Connected);
        var workConstraints = builder.Build();

        var workerRequest = new OneTimeWorkRequest.Builder(typeof(DataSyncWorker))
            .SetConstraints(workConstraints)
            .AddTag(DataSyncWorker.TAG)
            .Build();

        WorkManager.GetInstance(Microsoft.Maui.ApplicationModel.Platform.AppContext)
            .EnqueueUniqueWork(DataSyncWorker.TAG, ExistingWorkPolicy.Keep, workerRequest);

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@mariglenpupa
Comment options

Comment options

You must be logged in to vote
2 replies
@joseluisct
Comment options

@antmx
Comment options

Answer selected by omxie
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
8 participants