完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
1.通过读取电流节点的方式,获取电流。
电流节点:”/sys/class/power_supply/battery/BatteryAverageCurrent” 2.代码: .............................................................. import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; .............................................................. public class Xxxxx extends Activity{ ..................... private static final String CHARGER_CURRENT_NOW = "/sys/class/power_supply/battery/BatteryAverageCurrent"; .............................................................. private TextView mCurrent; .............................................................. public void onResume(){ .............................................................. mCurrent = (TextView)findViewById(R.id.current); .............................................................. try { mCurrent.setText(readCurrentFile(new File(CHARGER_CURRENT_NOW))+" mA"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } .............................................................. } public String readCurrentFile(File file) throws IOException { InputStream input = new FileInputStream(file); try { BufferedReader reader = new BufferedReader(new InputStreamReader( input)); StringBuilder *** = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { ***.append(line); } return ***.toString(); } finally { input.close(); } } } |
|
|
|
只有小组成员才能发言,加入小组>>
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-18 03:14 , Processed in 0.669041 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号