Home > front end >  Android WorkManager Network Constraint For Both Wifi and Data (Cellular)
Android WorkManager Network Constraint For Both Wifi and Data (Cellular)

Time:03-29

I am learning WorkManager and wondering if following the correct way of setting network constraint for both Wifi and data (cellular):

val constraints = Constraints.Builder().run {
    setRequiredNetworkType(NetworkType.UNMETERED)    //Wifi
    setRequiredNetworkType(NetworkType.METERED)      //data
    build()
}

CodePudding user response:

That's exactly the use case for the NetworkType.CONNECTED type:

Any working network connection is required for this work.

  • Related