【移动应用开发技术】怎么在Android 8.0中实现慢充和快充提示语_第1页
【移动应用开发技术】怎么在Android 8.0中实现慢充和快充提示语_第2页
【移动应用开发技术】怎么在Android 8.0中实现慢充和快充提示语_第3页
【移动应用开发技术】怎么在Android 8.0中实现慢充和快充提示语_第4页
【移动应用开发技术】怎么在Android 8.0中实现慢充和快充提示语_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】怎么在Android8.0中实现慢充和快充提示语

今天就跟大家聊聊有关怎么在Android8.0中实现慢充和快充提示语,可能很多人都不太了解,为了让大家更加了解,在下给大家总结了以下内容,希望大家根据这篇文章可以有所收获。1.慢充和快充提示语\frameworks\base\packages\SystemUI\res-keyguard\values-zh-rCN中文提示语<string

name="keyguard_plugged_in"

msgid="89308975354638682">"正在充电"</string>

<string

name="keyguard_plugged_in_charging_fast"

msgid="8869226755413795173">"正在快速充电"</string>

<string

name="keyguard_plugged_in_charging_slowly"

msgid="6637043106038550407">"正在慢速充电"</string>英文提示语\frameworks\base\packages\SystemUI\res-keyguard\values1.快充充电器充电-显示快速充电字符串<!--

When

the

lock

screen

is

showing

and

the

phone

plugged

in,

and

the

battery

is

not

fully

charged,

and

it's

plugged

into

a

fast

charger,

say

that

it's

charging

fast.

-->

<string

name="keyguard_plugged_in_charging_fast">Charging

rapidly</string>2.普通充电电器-显示充电,该同7.0及其以前特性<!--

When

the

lock

screen

is

showing

and

the

phone

plugged

in,

and

the

battery

is

not

fully

charged,

say

that

it's

charging.

-->

<string

name="keyguard_plugged_in">Charging</string>3.电脑端或者笔记本端显示-缓慢充电<!--

When

the

lock

screen

is

showing

and

the

phone

plugged

in,

and

the

battery

is

not

fully

charged,

and

it's

plugged

into

a

slow

charger,

say

that

it's

charging

slowly.

-->

<string

name="keyguard_plugged_in_charging_slowly">Charging

slowly</string>2.原理根据当前的最大电压和电流计算出电流速度,并进行分类为慢速充电,充电,快速充电2.1源代码中的原始数据•public

static

final

String

EXTRA_MAX_CHARGING_CURRENT

=

“max_charging_current”;

•public

static

final

String

EXTRA_MAX_CHARGING_VOLTAGE

=

“max_charging_voltage”;发送“电池广播”位置将最大电流和电压上发应用层,这里主要一些8.1以上新增的数据,7.0以前有这个数据但是framework层没有使用frameworks/base/services/core/java/com/android/server/BatteryService.java

//

发送电池广播事件

private

void

sendIntentLocked()

{

//

Pack

up

the

values

and

broadcast

them

to

everyone

final

Intent

intent

=

new

Intent(Intent.ACTION_BATTERY_CHANGED);

intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY

|

Intent.FLAG_RECEIVER_REPLACE_PENDING);

intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_CURRENT,

mBatteryProps.maxChargingCurrent);

intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE,

mBatteryProps.maxChargingVoltage);2.2adbshell查看linux的文件节点•获取当前的电流adb

shell

cat

/sys/class/power_supply/battery/current_max

adb

shell

cat

/sys/class/power_supply/battery/current_max

30000001•获取当前的电压adb

shell

cat

/sys/class/power_supply/battery/voltage_max

adb

shell

cat

/sys/class/power_supply/battery/voltage_max

50000001•具体源码system/core/healthd/BatteryMonitor.cpp

#define

POWER_SUPPLY_SYSFS_PATH

"/sys/class/"

POWER_SUPPLY_SUBSYSTEM

path.appendFormat("%s/%s/voltage_max",

POWER_SUPPLY_SYSFS_PATH,mChargerNames[i].string());2.3上层接收广播frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java重点看maxChargingMicroAmp和maxChargingMicroVolt的算法规则private

final

BroadcastReceiver

mBroadcastReceiver

=

new

BroadcastReceiver()

{

}

else

if

(Intent.ACTION_BATTERY_CHANGED.equals(action))

{

final

int

status

=

intent.getIntExtra(EXTRA_STATUS,

BATTERY_STATUS_UNKNOWN);

final

int

plugged

=

intent.getIntExtra(EXTRA_PLUGGED,

0);

final

int

level

=

intent.getIntExtra(EXTRA_LEVEL,

0);

final

int

health

=

intent.getIntExtra(EXTRA_HEALTH,

BATTERY_HEALTH_UNKNOWN);

final

int

maxChargingMicroAmp

=

intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT,

-1);

int

maxChargingMicroVolt

=

intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE,

-1);

final

int

maxChargingMicroWatt;

if

(maxChargingMicroVolt

<=

0)

{

maxChargingMicroVolt

=

DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT;

}

if

(maxChargingMicroAmp

>

0)

{

//

Calculating

muW

=

muA

*

muV

/

(10^6

mu^2

/

mu);

splitting

up

the

divisor

//

to

maintain

precision

equally

on

both

factors.

maxChargingMicroWatt

=

(maxChargingMicroAmp

/

1000)

*

(maxChargingMicroVolt

/

1000);

}

else

{

maxChargingMicroWatt

=

-1;

}

final

Message

msg

=

mHandler.obtainMessage(

MSG_BATTERY_UPDATE,

new

BatteryStatus(status,

level,

plugged,

health,

maxChargingMicroWatt));

mHandler.sendMessage(msg);2.4显示字符串frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java事件接收protected

class

BaseKeyguardCallback

extends

KeyguardUpdateMonitorCallback

{

public

static

final

int

HIDE_DELAY_MS

=

5000;

private

int

mLastSuccessiveErrorMessage

=

-1;

@Override

public

void

onRefreshBatteryInfo(KeyguardUpdateMonitor.BatteryStatus

status)

{

boolean

isChargingOrFull

=

status.status

==

BatteryManager.BATTERY_STATUS_CHARGING

||

status.status

==

BatteryManager.BATTERY_STATUS_FULL;

boolean

wasPluggedIn

=

mPowerPluggedIn;

mPowerPluggedIn

=

status.isPluggedIn()

&&

isChargingOrFull;

mPowerCharged

=

status.isCharged();

mChargingWattage

=

status.maxChargingWattage;

mChargingSpeed

=

status.getChargingSpeed(mSlowThreshold,

mFastThreshold);

updateIndication();

if

(mDozing)

{

if

(!wasPluggedIn

&&

mPowerPluggedIn)

{

showTransientIndication(computePowerIndication());

hideTransientIndicationDelayed(HIDE_DELAY_MS);

}

else

if

(wasPluggedIn

&&

!mPowerPluggedIn)

{

hideTransientIndication();

}

}

}

=====================================================================================================

public

static

class

BatteryStatus

{

public

static

final

int

CHARGING_UNKNOWN

=

-1;

public

static

final

int

CHARGING_SLOWLY

=

0;

public

static

final

int

CHARGING_REGULAR

=

1;

public

static

final

int

CHARGING_FAST

=

2;

public

final

int

status;

public

final

int

level;

public

final

int

plugged;

public

final

int

health;

public

final

int

maxChargingWattage;

public

BatteryStatus(int

status,

int

level,

int

plugged,

int

health,

int

maxChargingWattage)

{

this.status

=

status;

this.level

=

level;

this.plugged

=

plugged;

this.health

=

health;

this.maxChargingWattage

=

maxChargingWattage;

}

public

final

int

getChargingSpeed(int

slowThreshold,

int

fastThreshold)

{

return

maxChargingWattage

<=

0

?

CHARGING_UNKNOWN

:

maxChargingWattage

<

slowThreshold

?

CHARGING_SLOWLY

:

maxChargingWattage

>

fastThreshold

?

CHARGING_FAST

:

CHARGING_REGULAR;

}显示字符串frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationCon

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论