How to deal with battery optimization Huawei and Xiaomi?

I have an application that listens for notifications through NotificationListenerService . My application survives both the "Dose" mode and the application on almost any phone (if it is correctly configured, for example, an exception or a foreground service).

Then come Huawei and Xiaomi with their Android modifications to "improve battery life." They can interfere with working with background applications so badly that in a week or two the application needs to be reinstalled. Even cleansing data will not thaw the application. Even exceptions to their own “optimizations” do not allow this. Just completely disable all of their optimizations, for example. allowing "high-performance mode" can fix it. But users do not want to disable these options.

How do you deal with these cases? And how can we stop manufacturers from stopping messing with mainstream Android? Not to mention the ridiculous ANRs and crashes in Zygote

+5
source share
1 answer

Then come Huawei and Xiaomi with their Android modifications to "improve battery life."

Yes Xiaomi, Huawei and some other manufacturers have their own “Battery Saver” or “Security” layer, which kills or restricts background running applications in order to improve security / battery backups, unless the user selects your application in the appropriate device settings.

What I learned about Xiaomi is that they are familiar with famous apps like Facebook, Whatsapp, etc. But you cannot request Xiaomi to whitelist your application.

This can damage the background launch of applications so badly that after a week or two the application needs to be reinstalled. Even cleansing data will not thaw the application.

These vendor applications simply terminate your application process. Therefore, your application should behave in such a way that termination at any time should not create an inconsistent state.

In addition, you can always display a pop-up window for the user after installation, asking him to go and whitelist your application in battery saving mode. In Xiaomi, the user needs to select "Do not limit background activity", and also enable "Autostart" for your application. As far as I know, there is no other solution.

Let me know if you find one;)

Xiaomi app auto launch setup screen Xiaomi app battery saver setup screen

+2
source

Source: https://habr.com/ru/post/1273152/


All Articles