I'm wondering if there's any way in React Native that allows us to know if user has been selected "Battery Optimized" for our app?
How to check if my app has been configured battery optimized on Android?
1.9k views Asked by Isaac At
1
I'm wondering if there's any way in React Native that allows us to know if user has been selected "Battery Optimized" for our app?
in native android,You can use
PowerManager.isIgnoringBatteryOptimizations()
boolean to determine if an application is already ignoring optimizations ie whether the app is on the whitelist .and then in js
https://github.com/vikeri/react-native-background-job/ is a good library that sees all the edge cases of background execution
If you want to ask user to turn it off - ask for
Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
permissionfrom
https://developer.android.com/reference/android/provider/Settings#ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS