In the new Android M
build, the Battery Optimization feature will stop the app on certain condition to save battery, but for the VOIP
apps that need to stay alive all the time, this feature cause troubles for the developer.
Currently there is one way to bypass the optimization, which is set the app to ignore optimizations,but too many steps need to be done.
My question is, is there a way to jump to ignore optimization page of specific App, and how can I know whether my app is excluded from optimization?
WARNING: It seems Google doesn't allow apps on the Play Store to do this. See the comments below.
Based on the AndroidManifest.xml extracted from Settings.apk in the MPA44I build, it would seem you might be able to do what you want by something like the intent below.
From XML:
<intent
android:action="android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"
android:targetPackage="com.android.settings"
android:data="package:PUT_YOUR_PACKAGE_NAME_HERE" />
From code:
try {
Intent intent = new Intent(android.provider.Settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:PUT_YOUR_PACKAGE_NAME_HERE"));
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
Note that I have not had time to verify this in practice myself but the approach is the same as I use in one of my apps to launch app-specific settings menus. Still, I hope it helps.
Google Allow this based on few conditions Check Section "Support For Other Use Cases"
here
Also check White List Conditions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With