I'm trying to start an activity for whitelisting an app on the emulator (API 25), but I keep getting an error saying:
Caused by: android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS }
Here's my code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
startActivity(intent);
}
Anyone know why this error is thrown?
Take a look at the Android Developer Documentation: https://developer.android.com/reference/android/provider/Settings#ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
Looks like you are missing this part:
Input: The Intent's data URI must specify the application package name to be shown, with the "package" scheme. That is "package:com.my.app"
The following line should help:
intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName()));
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