android-workmanager

PeriodicWorkRequest with WorkManager

天大地大妈咪最大 提交于 2020-02-20 09:02:50
问题 Well as WorkManager is newly introduce in Google I/O, I'm trying to use workmanager to perform task periodically, What I'm doing is, Scheduling the work using PeriodicWorkRequest as following : Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build(); PeriodicWorkRequest build = new PeriodicWorkRequest.Builder(SyncJobWorker.class, MY_SCHEDULE_TIME, TimeUnit.MILLISECONDS) .addTag(TAG) .setConstraints(constraints) .build(); WorkManager instance =

Uploading large bitmaps using WorkManager

血红的双手。 提交于 2020-02-06 06:06:17
问题 I'm trying to use WorkManager to upload a bitmap to the server. Basically the user takes a picture and presses a button to upload it to the server. However, the problem comes when I try to serialise the bitmap using the Data.Builder class of Work Manager, which has a limit of 10240 bytes. Therefore, if I do the following: val data = Data.Builder() //Add parameter in Data class. just like bundle. You can also add Boolean and Number in parameter. data.putString(IMAGE_NAME, identifier) data

how to pass object as input to WorkManager without Serialization?

江枫思渺然 提交于 2020-01-24 19:54:10
问题 I need to pass complex object to WorkManager. Or I need to serialize object which contains Livedata and Date. It throws java.lang.IllegalArgumentException: Key cabinId2 has invalid type class com.example.sonyadmin.data.Task val data = workDataOf("cabinId2" to task) val uploadWorkRequest = OneTimeWorkRequestBuilder<WManager>() .setInputData(data) .build() 回答1: WorkManager's Data class only accepts some specific types as values as explained in the reference documentation: A persistable set of

Why use the OneTimeWorkRequest's setInitialDelay() function of the WorkManager, the delay does not apply when changing the device's time

南笙酒味 提交于 2020-01-22 16:00:08
问题 I would like to use WorkManager to update the DB every 24 hours from midnight. First, I'm understand that the Workmanager's PeriodicWorkRequest does not specify that the worker should operate at any given time. So I used OneTimeWorkRequest() to give the delay and then put the PeriodicWorkRequest() in the queue, which runs every 24 hours. 1.Constraints private fun getConstraints(): Constraints { return Constraints.Builder() .setRequiredNetworkType(NetworkType.NOT_REQUIRED) .build() } 2

Notifications not running when is app is swiped from recents (Samsung S9 running API 27)

北慕城南 提交于 2020-01-16 19:08:46
问题 I've looked through countless threads regarding the same topic, but have not found any working answers. My app has min API level 21, target API level 29, and I'm testing on a Samsung S9 with Android Oreo (8.1, API 27). None of the methods for pushing notifications (that I've found) seem to be working when the application is swiped away from recents. In all the methods I tried, all notifications are working when the application is left on. What I've tried: Scheduling notifications with

Notifications not running when is app is swiped from recents (Samsung S9 running API 27)

我是研究僧i 提交于 2020-01-16 19:07:12
问题 I've looked through countless threads regarding the same topic, but have not found any working answers. My app has min API level 21, target API level 29, and I'm testing on a Samsung S9 with Android Oreo (8.1, API 27). None of the methods for pushing notifications (that I've found) seem to be working when the application is swiped away from recents. In all the methods I tried, all notifications are working when the application is left on. What I've tried: Scheduling notifications with

My app freezes when I make a network request in background thread (using CoroutineWorker & Work manager)

邮差的信 提交于 2020-01-14 05:32:48
问题 I'm trying to set wallpaper on a periodic basis and for that, I'm using the Work manager. When I make a network request from a background thread (CoroutineWorker), my app UI freezes till network request & set wallpaper completes. I've already tried to run this using Async Task as well, but no use. @WorkerThread override suspend fun doWork(): Result = coroutineScope { try { MainService.createRetrofitService().getRandomPhoto(map) .enqueue(object : Callback<RandomPhotoModel> { override fun

How to implement Dagger for worker classes in Dagger 2.16 ?('android.arch.work:work-runtime')

怎甘沉沦 提交于 2020-01-14 04:36:41
问题 How to implement Dagger for worker classes in Dagger 2.16? public class SyncWorker extends Worker { @Inject ISettingRepository settingRepository; @NonNull @Override public Result doWork() { sync(); return Result.SUCCESS; } private void sync() { } } my AppComponent @Singleton @Component(modules = { AndroidSupportInjectionModule.class, BaseModule.class, ApiModule.class, UserDatabaseModule.class, SaleDatabaseModule.class, AppModule.class, ActivityBuilderModule.class }) public interface

How to pass Complex Types of Objects to WorkManager in android. i.e lists, maps, POJO

懵懂的女人 提交于 2020-01-13 05:19:06
问题 WorkManager is a library used to enqueue work that is guaranteed to execute after its constraints are met. WorkManager allows observation of work status and the ability to create complex chains of work. Valid types supported are only: Boolean, Integer, Long, Double, String, and array versions of each of those types. // Define the Worker class: public class MathWorker extends Worker { // Define the parameter keys: public static final String KEY_X_ARG = "X"; public static final String KEY_Y_ARG

How to ensure PeriodicWorkRequests are called on device reboot on Android N and upwards

走远了吗. 提交于 2020-01-11 07:25:10
问题 I recently tried to use the WorkManager 's PeriodicWorkRequest s as a surefire way of getting user location updates periodically in the background. The library met my requirements and this particular detail got my attention: Guarantees task execution, even if the app or device restarts Having implemented and tested it, I tried rebooting my device and noticed the Log message and App Notification never showed up. Naturally, I did some research and stumbled upon this: PeriodicWorkRequest not