I'm testing one application in one Android 6 where I need to pass the DOZE, for that I want to request to the users accept the igore of battery optimization.
As in project AntiDoze, but when I run in a virtual device I do not have any problem, but when I pass to the Samsung I get:
FATAL EXCEPTION: main
Process: com.commonsware.android.antidoze, PID: 21135
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.commonsware.android.antidoze/com.commonsware.android.antidoze.EventDemoActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS dat=package:com.commonsware.android.antidoze }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
Any idea how to pass this problem?
The code important from the link is:
if (Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP_MR1) {
String pkg=getPackageName();
PowerManager pm=getSystemService(PowerManager.class);
if (!pm.isIgnoringBatteryOptimizations(pkg)) {
Intent i=
new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setData(Uri.parse("package:"+pkg));
startActivity(i);
}
}
In the manifest I have
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
In Android, there's a feature called "Doze" meaning dose. It was first launched in Marshmellow. When your phone is idle or when the screen is off, Doze shuts down background processes to save battery life. However, Doze mode also interrupts ride recording in the background to save battery.
Tap the more button on the action bar at the top right, and choose Optimize battery usage. 5. On the Optimize Battery Usage screen, switch to the All apps list from the drop-down to see all of the apps on your device. Turn off to exclude Nine from the Doze feature.
The Battery optimization screen allows you to configure Android's Doze mode, selecting which apps may be optimized by this feature. This screen can usually be reached by the overflow menu (often the three dots icon) in the Battery settings (or Battery usage on some devices).
Catch the ActivityNotFoundException
and display your own UI to the user, asking them to go to the Settings app and add your app to the battery optimization whitelist. While the docs do not say this specifically for this Intent
action, most of the Settings.ACTION_*
values mention "In some cases, a matching Activity may not exist, so ensure you safeguard against this".
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