Ras*_*eed 6 android android-intent battery-saver android-9.0-pie
我需要意图“不优化” ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS 的设置页面。
但是当我将其更改为“不优化并返回”时,设置不会保存。它仍然会在“优化”列表中
设备:一加 5 操作系统:Android 9.0
代码 :
startActivityForResult(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS), 0);
Run Code Online (Sandbox Code Playgroud)
问题:设置未保存。
还有“电池优化应用程序列表”可用的意图吗?
尝试此请求REQUEST_IGNORE_BATTERY_OPTIMIZATIONS。
将其添加到清单中
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
使用此功能来请求优化。
public static void BatteryOptimization(Context context){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent();
String packageName = context.getPackageName();
PowerManager pm = (PowerManager) context.getSystemService(POWER_SERVICE);
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + "YOUR_PACKAGE_NAME"));
context.startActivity(intent);
}
}
}
Run Code Online (Sandbox Code Playgroud)它将要求用户将您的应用程序从电池优化中排除。
| 归档时间: |
|
| 查看次数: |
6391 次 |
| 最近记录: |