Android Question IGNORE BATTERY OPTIMIZATIONS

ilpesce

Member
Licensed User
hello to everyone
you can implement in B4A this request to the user?
REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
thanks in advance
 

AndOrNot

Well-Known Member
Licensed User
It is in java, if you mean this.
It could be not difficult to port it

B4X:
Intent intent = new Intent();
String packageName = context.getPackageName();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm.isIgnoringBatteryOptimizations(packageName))
    intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else {
    intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
    intent.setData(Uri.parse("package:" + packageName));
}
context.startActivity(intent);
 
Upvote 0

ilpesce

Member
Licensed User
Only to have the alerts even with the screen off
Thank andornot for the tip, and erel for the important information.
This is a quagmire in which I will not go
will be the users to exclude my application from optimization
I realized that there are much larger interests which the battery life ...
 
Upvote 0

ilpesce

Member
Licensed User
Hello Erel
For years I used "StartServiceAt / StartServiceAtExact" to wake up the device every minute and update the status of the app. and check if they were set alarms or reminders for that time, then I brought back to sleep the device, all this very little affected the battery life.
With the latest Android versions are forced to use "StartServiceAtExactWhileIdle", I hope will you implement as soon as possible in B4A ... :)
which still to run on all devices you need the application to be excluded from battery optimization (not counting the various alerts that are sent to the user by the operating system ...). as you solve?
greetings to all
 
Upvote 0
Top