Hello,
Welcome to our Microsoft Q&A platform!
REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
is not a dangerous permission. You do not need, or want, any of that code(do not need request runtime permission). Here is Google's document.
Permission an application must hold in order to use ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. This is a normal permission: an app requesting it will always be granted the permission, without the user needing to approve or see it.
Requesting REQUEST_IGNORE_BATTERY_OPTIMIZATIONS grants you the authority, from a security standpoint, to start an activity with an ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent. Be sure to include your app's package as the Uri, Here is code
private void Button1_Click(object sender, System.EventArgs e)
{
Intent intent = new Intent();
string packageName = this.PackageName;
PowerManager pm = (PowerManager)this.GetSystemService(Context.PowerService);
if (pm.IsIgnoringBatteryOptimizations(packageName))
intent.SetAction(Android.Provider.Settings.ActionIgnoreBatteryOptimizationSettings);
else
{
intent.SetAction(Android.Provider.Settings.ActionRequestIgnoreBatteryOptimizations);
intent.SetData(Uri.Parse("package:" + packageName));
}
StartActivity(intent);
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.