下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、android 手机电池电量的应用原理概述:手机电池电量的猎取在应用程序的开发中也很常用,系统中手机电池电量发生变幻的消息是通过intent广播来实现的,常用的intent的action有 intent.action_battery_changed(电池电量发生转变时)、intent.action_battery_low(电池电量达到下限时)、和intent.action_battery_okay(电池电量从低复原到高时)。当需要在程序中猎取电池电量的信息时,需要为应用程序注册broadcastreceiver组件,当特定的action大事发生时,系统将会发出相应的广播,应用程序就可以通过br
2、oadcastreceiver来接受广播,并举行相应的处理。main.xml布局文件android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">android:layout_width="fill_parent"android:layout_height="wrap_content"android:texton="停止猎取电量信息"
3、android:textoff="猎取电量信息" />android:layout_width="fill_parent"android:layout_height="wrap_content" />复制代码batteryactivity类package com.ljq.activity;import android.app.activity;import android.content.broadcastreceiver;import android.content.context;import android.cont
4、ent.intent;import android.content.intentfilter;import android.os.bundle;import android.widget.compoundbutton;import android.widget.textview;import android.widget.togglebutton;import android.widget.compoundbutton.oncheckedchangelistener;public class batteryactivity extends activity private togglebutt
5、on tb=null;private textview tv=null;private batteryreceiver receiver=null;overridepublic void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate);setcontentview(r.layout.main);receiver=new batteryreceiver();tv=(textview)findviewbyid(r.id.tv);tb=(togglebutton)findviewbyid(r.id.tb);
6、tb.setoncheckedchangelistener(new oncheckedchangelistener()public void oncheckedchanged(compoundbutton compoundbutton, boolean ischecked) /猎取电池电量if(ischecked)intentfilter filter=new intentfilter(intent.action_battery_changed);registerreceiver(receiver, filter);/注册broadcastreceiverelse /停止猎取电池电量unreg
7、isterreceiver(receiver);tv.settext(null););private class batteryreceiver extends broadcastreceiveroverridepublic void onreceive(context context, intent intent) int current=intent.getextras().getint("level");/获得当前电量int total=intent.getextras().getint("scale");/获得总电量int percent=current*100/total;tv.settext("现在的电量是"+percent+"%。&quo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 基于MATLABSimulink倒立摆稳定性研究课程设计
- 教育行为分析工具课程设计
- 北京营地课程设计
- 深度强化学习AI未来课程设计
- 草莓采摘项目课程设计
- UWB室内定位系统仿真测试课程设计
- 产教融合课程设计
- 管道、架线工程测量服务市场需求变化趋势与商业创新机遇分析报告
- 2026 年网格员考试试题及答案
- 2025年天津市(56所)马克思主义基本原理概论期末考试模拟题附答案培优卷
- 发展对象公示情况报告单
- 新建铁路段站前工程架子队管理办法
- 中药湿热敷技术评分标准
- 征兵体检培训试题及答案
- 英语句子成分及五种简单句PPT
- GB/T 880-2008无头销轴
- GB/T 8685-2008纺织品维护标签规范符号法
- GB/T 6682-2008分析实验室用水规格和试验方法
- GB/T 15065-2009电线电缆用黑色聚乙烯塑料
- 农业生物环境工程第 温室设施环境调节与控制1
- 化学品安全技术说明书MSDS(液氨)
评论
0/150
提交评论