android 优化耗电量
来源:互联网 发布:软件项目监理细则 编辑:程序博客网 时间:2024/04/29 01:15
作为app开发者,或许很少有人会注意app对电量的损耗,但是用户对电量可是很敏感的,app做好电量损耗的优化会为自己的app加分不少。
如果是一个好的负责任的开发者,就应该限制app对电量的影响,当没有网络连接的时候,禁用后台服务更新,当电池电量低的时候减少更新的频率,确保自己的app对电池的影响降到最低。当电池充电或者电量比较饱和时,可以最大限度的发挥app的刷新率
1
<
receiver
android:name
=
".PowerConnectReceiver"
>
2
<
intent-filter
>
3
<
action
android:name
=
"android.intent.action.ACTION_POWER_CONNECTED"
/>
4
<
action
android:name
=
"android.intent.action.ACTION_POWER_DISCONNECTED"
/>
5
</
intent-filter
>
6
</
receiver
>
01
public
class
PowerConnectionReceiver
extends
BroadcastReceiver {
02
@Override
03
public
void
onReceive(Context context, Intent intent) {
04
int
status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -
1
);
05
boolean
isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
06
status == BatteryManager.BATTERY_STATUS_FULL;
07
08
int
chargeFlag = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -
1
);
09
boolean
usbCharge = chargeFlag == BATTERY_PLUGGED_USB;
10
boolean
acCharge = chargeFlag == BATTERY_PLUGGED_AC;
11
}
12
}
1
//获取程序是否充电
2
3
int
status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS,-
1
);
4
5
boolean
isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||status == BatteryManager.BATTERY_STATUS_FULL;
1
// 充电方式,usb还是电源
2
int
chargeFlag = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -
1
);
3
boolean
usbCharge = chargeFlag == BATTERY_PLUGGED_USB;
4
boolean
acCharge = chargeFlag == BATTERY_PLUGGED_AC;
1
不断的检测电量也会影响电池的使用时间,我们可以这样做
1
<
receiver
android:name
=
".BatteryLevelReceiver"
>
2
<
intent-filter
>
3
<
action
android:name
=
"android.intent.action.ACTION_BATTERY_LOW"
/> <
action
android:name
=
"android.intent.action.ACTION_BATTERY_OKAY"
/> </
intent-filter
>
4
</
receiver
>
当电量低或者满时会触发
有时间再写确定和监测连接状态
- android 优化耗电量
- Android性能优化(四),网络优化 && 耗电量优化
- android 耗电量
- 【android】android耗电量测试
- Android耗电量测试
- Android App耗电量统计
- android耗电量测试
- Android-耗电量测试
- Android App 耗电量统计
- Android App耗电量统计
- android耗电量检测
- 降低Android应用程序的耗电量
- 控制Android应用程序的耗电量
- android应用开发控制耗电量
- Android中App耗电量统计
- 控制Android应用程序的耗电量
- 控制Android应用程序的耗电量
- android中App耗电量统计
- java钱币转换 123 一百二十三和壹佰贰拾叁元
- SQL server 2008数据库的备份与还原
- Oracle的Number型
- 写给我们这些浮躁的90后程序员
- 关于django多线程问题解决
- android 优化耗电量
- 浙江大华2011.10.10校园招聘会笔试题
- uva 10128 队伍
- TFileStream文件流读写
- js常用语句
- Node.js开发指南之二:核心模块介绍
- fgets(char *s, int n, FILE *stream)的注意事项
- .解决bug:The content of the adapter has changed but ListView did not receive a notification .
- 运行时改变Button的android:drawableTop