gpt4 book ai didi

android - 如何在请求忽略电池优化后手动更改电池优化设置?

转载 作者:行者123 更新时间:2023-11-29 23:22:21 48 4
gpt4 key购买 nike

我使用以下代码请求忽略应用程序的电池优化。我可以成功请求权限。我能够使用 isIgnoringBatteryOptimizations() 检测应用程序是否在系统的白名单中。

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>


Intent intent = new Intent();
String packageName = context.getPackageName();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

if (pm.isIgnoringBatteryOptimizations(packageName))
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else
{
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
}
context.startActivity(intent);

我可以看到一个对话框,类似于“是否让应用程序始终在后台运行?”,然后我单击"is"。我假设它会将我的应用程序添加到系统电池优化白名单中。

这是我的问题。文档提到用户可以在设置 > 电池 > 电池优化 中手动配置列表。所以我希望一旦我请求并授予权限,我就可以在系统设置中看到它,并且我应该能够手动将其删除。但我什么也看不见。我没有看到请求和系统设置中的列表之间有任何关系。

他们共享同一个列表吗?如果它们不相同,它们是等价的吗?

最佳答案

So I expected that once I request and granted the permission, I can see it on System Settings

事实并非如此。文档 ( https://developer.android.com/training/monitoring-device-state/doze-standby#support_for_other_use_cases) 说:

An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog to let the user add the app to the whitelist directly, without going to settings. The app fires a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog.

这只是启动对话框的权限。该应用不会自动列入白名单。用户必须明确将其添加到列表中的任何方式。

Do they share the same list? are they equivalent if they are not the same?

只有一个列表。

关于android - 如何在请求忽略电池优化后手动更改电池优化设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54077966/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com