Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Activity found to handle Intent: ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

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?

like image 821
John M. Avatar asked Oct 16 '22 17:10

John M.


1 Answers

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()));
like image 94
arnoduebel Avatar answered Nov 15 '22 06:11

arnoduebel