[英]How force the app to opt out of battery saver mode when the service is ON?
The expected behavior is that the app will be running all the time when it's in ON state.预期的行为是应用程序在处于 ON 状态时将一直运行。 Some phones put the app in background mode when the app is not active for some time.
当应用程序一段时间不活动时,某些手机会将应用程序置于后台模式。 I want the app to be running all the time even its in standby mode(standby mode means when we press the home button the app will go to background. and it will run for some time).
我希望该应用程序即使在待机模式下也能一直运行(待机模式意味着当我们按下主页按钮时,该应用程序将进入后台。它会运行一段时间)。
I found following code and I tried that我找到了以下代码并尝试了
PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
String packageName = "org.traccar.client";
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent i = new Intent();
if (!powerManager.isIgnoringBatteryOptimizations(packageName)) {
i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
i.setData(Uri.parse("package:" + packageName));
startActivity(i);
}
else{
i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
i.setData(Uri.parse("package:" + packageName));
startActivity(i);
}
}
Even after working with the code the default state is Battery Saver(recommended)即使在使用代码后,默认状态也是 Battery Saver(推荐)
I want the app in No Restriction mode once the app is opened, any solution for this?一旦应用程序打开,我希望应用程序处于无限制模式,对此有什么解决方案?
The code you use is for battery optimization .您使用的代码用于电池优化。 Settings-->Batery-->Three Dots Menu Item (...)--->Battery Optimization-->(Choose an app from list)--->Optimize/ Don't optimize.
设置-->电池-->三点菜单项(...)--->电池优化-->(从列表中选择一个应用程序)--->优化/不优化。
By choosing Don't optimize
you are essentially bypassing Doze
, not app standby
.通过选择
Don't optimize
您实际上绕过了Doze
,而不是app standby
。
Also be advised that doing this programmatically as you do may result in Google taking your app off the store .另请注意,以编程方式执行此操作可能会导致 Google 下架您的应用程序。 It is safer to do it manually following the path i described above.
按照我上面描述的路径手动执行更安全。
More on Doze
and App Standby
here在此处了解有关
Doze
和 App Standby
更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.