WorkManager在小米设备上为什么不工作?

huangapple go评论72阅读模式
英文:

Why doesn't WorkManager work in Xiamo devices?

问题

Short Version: WorkManager 在 MIUI 设备上不起作用!(如标题所述)

Detailed Version: 我已经搜索了几天关于这个问题,感到沮丧。在我的应用程序(离线工作)中,我应该在一天中的某个特定时间发送通知。然而,似乎根本没有适当的方法来做到这一点。我找到的最后一种方法是使用 WorkManager,在大多数设备上似乎运行正常(当应用程序在 Android O 之后被杀死时,闹钟管理器根本不起作用)。但在小米设备上,WorkManager 不起作用。只有在手动允许一些功能后,WorkManager 才能工作(自动启动和不限制电池优化),这并不是一个好的解决方案,因为在不同的设备上位置不同,对普通用户来说很难找到。

如果您遇到了相同的问题,您能告诉我如何解决吗?
如果 WorkManager 在后台不起作用,它有什么意义呢?

P.S.:当应用程序打开时,WorkManager 可以正常工作。它还可以在模拟器上正常工作,所以实施上没有问题。

这是我用来发送请求的代码:

PeriodicWorkRequest workRequest =
        new PeriodicWorkRequest.Builder(UploadWorker.class, 24 , TimeUnit.HOURS)
                .setInitialDelay(1, TimeUnit.MINUTES)
                .build();

WorkManager.getInstance(getContext())
        .enqueueUniquePeriodicWork("FIRST_TIMER", ExistingPeriodicWorkPolicy.REPLACE,workRequest);
英文:

Short Version: WorkManager doesnt work on MIUI devices! (as stated in the title)

Detailed Version: I have been searching on this topic for days and I'm frustrated. In my app (which is working offline) I am supposed to send notification on certain hours of the day. However it seems like there is no proper way of doing this at all. The last approach I found was using the WorkManager which seemed to work fine on most devices (alarmmanager doesnt work at all when the app is killed after android O). But in Xiamo devices, the WorkManager doesn't work. Only if you manually allow some feature the WorkManager works (auto start and no restrictions for battery optimizatino) which is not a good solution as their location is different in different devices and is hard to find for normal users.

If you faced the same problem, can you tell me how to fix it?
what is the point of WorkManager if doesn't work on background?!

P.S. : Workmanager works fine when the app is open. it also works fine on the emulator so there is no problem in the implementation.

Here is the code I used to send the request:

 PeriodicWorkRequest workRequest =
            new PeriodicWorkRequest.Builder(UploadWorker.class, 24 , TimeUnit.HOURS)
                    .setInitialDelay(1, TimeUnit.MINUTES)
            .build();

    WorkManager.getInstance(getContext())
            .enqueueUniquePeriodicWork("FIRST_TIMER", ExistingPeriodicWorkPolicy.REPLACE,workRequest);

答案1

得分: 1

使用Android 6(Marshmallow),Google引入了Doze模式到基本的Android系统,试图统一各种Android手机的省电功能。

不幸的是,一些制造商(例如小米、华为、一加甚至三星..)似乎没有理解这一点,他们都有自己的电池节省功能,通常编写得很差,只是表面上省电,但有副作用。

请查看此答案以获取更多详细信息:https://stackoverflow.com/a/62929697/3995126

英文:

With Android 6 (Marshmallow), Google has introduced Doze mode to the base Android, in an attempt to unify battery saving across the various Android phones.

Unfortunately, some manufacturers (e.g. Xiaomi, Huawei, OnePlus or even Samsung..) did not seem to catch that ball and they all have their own battery savers, usually very poorly written, saving battery only superficially with side effects.

Please check this answer for more details : https://stackoverflow.com/a/62929697/3995126

huangapple
  • 本文由 发表于 2020年8月1日 19:08:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/63204512.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定