when run this code that exception throw
Intent intent=new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); //intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); //intent.setData(Uri.parse("package:" + getPackageName()));
//intent.addCategory(Intent.CATEGORY_ALTERNATIVE); Uri uri = Uri.fromParts("package", getPackageName(), null); intent.setData(uri); startActivity(intent); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
2022-03-08 22:55:45.172 3715-3715/com.example.batterop E/Error: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS dat=package:com.example.batterop }
Add in the Manifest file:
In Kotlin use like this: