androidandroid-jetpackandroid-workmanagerandroid-networking

Android WorkManager Network Constraint For Both Wifi and Data (Cellular)


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()
}

Solution

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

    Any working network connection is required for this work.