AlexSJC
发布于 2023-11-12 / 11 阅读
0
0

Xamarin.Android 请求忽略电池优化

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
{
    PowerManager pm = (PowerManager)GetSystemService(PowerService);
    if (!pm.IsIgnoringBatteryOptimizations(PackageName))
    {
        Intent intent = new(Settings.ActionRequestIgnoreBatteryOptimizations);
        intent.SetData(Android.Net.Uri.Parse($"package:{PackageName}"));
        StartActivity(intent);
    }
}

https://developer.android.google.cn/training/monitoring-device-state/doze-standby?hl=zh-cn#support_for_other_use_cases


评论