1

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);
Keivan.k
  • 548
  • 6
  • 21
  • 2
    Does this answer your question? [Work Manager on chinese ROMs like Xiaomi and oppo, when under battery optimization, increase the scheduled delay of work by several hours](https://stackoverflow.com/questions/59906497/work-manager-on-chinese-roms-like-xiaomi-and-oppo-when-under-battery-optimizati) – kelvin Aug 01 '20 at 11:15
  • That is basically asking the same question. it seems like there is actually no way to solve this problem rather than sending complaintes to google! – Keivan.k Aug 01 '20 at 11:51
  • It seems like that is the only answers, that there is no way but to ask users to give the permission mannually! – Keivan.k Aug 01 '20 at 12:19

1 Answers1

1

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

kelvin
  • 1,480
  • 1
  • 14
  • 28
  • I see but what is the solution? that doesn't really sound good. Asking users to manually enable some options which are not even universal! – Keivan.k Aug 01 '20 at 11:52
  • just like you said . there isn't any solution that works properly on every device. – kelvin Aug 01 '20 at 11:56
  • 1
    funny thing is that when you remove apps from background by clicking X on recent apps on Xiaomi devices : even their own Music player stops – kelvin Aug 01 '20 at 11:59
  • 1
    Yes, but I still have some apps that are sending notifications on exact times (and they are not famous ones like facebook, whatsapp etc) I have no idea how they are doing it – Keivan.k Aug 01 '20 at 16:30