android 电池充电曲线,在Android中,有没有办法让电池充电?

试试这段代码,可能会对你有所帮助:

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){

@Override

public void onReceive(Context arg0,Intent intent) {

// TODO Auto-generated method stub

//this will give you battery current status

int level = intent.getIntExtra("level",0);

contentTxt.setText(String.valueOf(level) + "%");

int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,-1);

textView2.setText("status:"+status);

boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||

status == BatteryManager.BATTERY_STATUS_FULL;

textView3.setText("is Charging:"+isCharging);

int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED,-1);

textView4.setText("is Charge plug:"+chargePlug);

boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;

boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

textView5.setText("USB Charging:"+usbCharge+" AC charging:"+acCharge);

}

};

在主类中注册这个使用:

this.registerReceiver(this.mBatInfoReceiver,new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值