首先,我们需要检查当前应用程序的电池优化状态。 importandroid.content.Context;importandroid.content.Intent;importandroid.os.Build;importandroid.provider.Settings;publicclassBatteryOptimizationChecker{publicstaticbooleanisBatteryOptimizationEnabled(Contextcontext){if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){retu...
请使用以下代码: publicvoidrequestBatteryOptimizationDisable(Contextcontext){if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){// 前往电池优化设置页面Intentintent=newIntent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);intent.setData(Uri.parse("package:"+context.getPackageName()));context.startActi...
Cloud Studio代码运行 publicclassMainActivityextendsAppCompatActivity{publicstaticfinal StringTAG="Battery_Performance.MainActivity";@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 引导用户打开白名单WhiteListUtils.addWhiteList(...
1. App程序可发送action为ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS的intent引导用户进入设置界面将应用程序设置进白名单列表里。 2. 应用程序还可以使用AREQUEST_IGNORE_BATTERY_OPTIMIZATIONS权限来触发一个系统对话来让用户添加到白名单里,而无需进入设置界面去设置。 当然,官方也提供用户把你的App移除电池优化白名单...
isIgnoringBatteryOptimizations(context.getPackageName()); // 如果没有在白名单中 , 弹出对话框 , 引导用户设置白名单 if(!isInWhiteList){ // 弹出白名单设置对话框 Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); context.startActivity(intent); } } } } Activity 中调...
测试App Standby模式 步骤1-3同测试Doze模式 运行以下adb命令迫使系统进入App Standby模式: $ adb shell dumpsys battery unplug $ adb shell am set-inactive true 模拟唤醒你的应用程序使用以下命令: $ adb shell am set-inactive false $ adb shell am get-inactive ...
battery historian分析 原创图片.png (因为我之前测试时间比较短,所以这里我借了以前看的文章保存的一张图片) 在该图中特别感兴趣的是电池水平的黑色线,水平,下降趋势线,在y轴上测量。例如,在电池电平线的最开始,大约在早上1:20,可视化显示电池电量相对急剧下降。
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)); //让用户直接转到电池优化设置界面,以便他们在其中添加该应用。 对话框让用户选择 具有REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 权限的应用可以触发一个系统对话框,让用户直接将该应用添加到白名单,而无需转到“设置”。此类应用将通过触发 ...
Here's info on Adaptive battery and Battery Optimization, both of which help conserve battery power on your Motorola device.
An app can fire the ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS intent to take the user directly to the Battery Optimization, where they can add the app. An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog to let the user add the app to the whitelist...