安卓手机电池寿命检测(MIUI11小米查看电池损耗代码)

  • 时间:
  • 浏览:86
  • 来源:奥一装修网

手机电池寿命检测app

Android系统通过广播接受电池状态。以下是我编写的一个简单的电池管理项目。 广播接受类BatteryReceiver如下:package com。lml。batteryshow; import java。util。HashMap; import java。util。Map; import android。content。BroadcastReceiver; import android。content。Context; import android 。content。Intent; import android。os。BatteryManager; import android。os。Message; public类BatteryReceiver扩展了BroadcastReceiver {消息消息; Map map = null; @覆盖public void onReceive(上下文上下文,意图意图){String action = intent。getAction(); if(action。equals(Intent。ACTION_BATTERY_CHANGED)){map = new HashMap(); / **剩余电池电量* /map。put(“ level”,Intent。getIntExtra(“ level”,0)+“”); / **获取完整的电池电量* /map。put(“ scale”,intent。getIntExtra(“ scale”,0)+“”); / **获得电池技术支持* /map。put(“技术”,intent。getStringExtra(“技术”)); / **获取电池状态* // **获取电源信息* /map。put(“ plugType”,intent。getIntExtra(“ plugged”,0)+“”); / **获取电池健康状态* /map。put(“ health”,Intent。getIntExtra(“ health”,BatteryManager。BATTERY_HEALTH_UNKNOWN)+“”); / **获取电池电压* /map。put(“ voltage”,intent。getIntExtra(“ voltage”,0)+“”); / **获取电池温度* /map。put(“温度”,intent。getIntExtra(“温度”,0)+“”); }if(map!= Null){message = new Message(); message。obj =地图; MainActivity。handler1。dispatchMessage(消息); }}}MainClass的MainActivity代码实现如下:package com。lml。batteryshow; import java。text。DecimalFormat; import java。util。Map; import android。os。Bundle; import android。os。Handler; import android。os。Message; import android。os。SystemClock; import android。app。Activity; import android。content。Intent; import android。content。IntentFilter; import android。widget。TextView;/ **电池状态* /私人TextView battery_Status;

安卓手机电池健康度

/ **电池允许状态* /私人TextView battery_Run_Status; / **电池电压* /私人TextView battery_Voltage; / **电池温度* /私人TextView battery_Temperature; / **电池技术* /私人TextView电池_技术; / **电池运行时间* /私人TextView电池时间; / **电池容量* /私人TextView battery_Level; Thread thread; public static Handler handler1; public Handler handler2; BatteryReceiver接收器; @重写受保护的void onCreate(捆绑的saveInstanceState)(super。onCreate(savedInstanceState);setContentView(R。layout。activity_main);init();线程=新线程(可运行);thread。start() ;regReceiver();handler1 = new Handler(){@覆盖public void handleMessage(消息msg){MainActivity。this。handleMessage(msg);}};/ **设置启动时间* / handler2 =新的Handler(){} else {battery_Run_Status。setText(“电池运行状况;常规”); }/ **设置电池电压* /battery_Voltage。setText(“电池电压:” + map。get(“电压”)+“ mV”); / **设置电池温度* /double temp = Double。parseDouble(map。get(“温度”)); battery_Temperature。setText(“电池温度:” +(温度/ 10)+“°C”); / **获取完整的电池电量* /double scale = Double。parseDouble(map。get(“ scale”)); / **获取剩余电池电量* /double level = Double。parseDouble(map。get(“ level”)); = =级别/比例String strPer = optionNum(per); / **设置电池电量* /battery_Level。setText(“电池电量:” + Double。parseDouble(strPer)* 100 +“%”); / **设置电池技术* /battery_Technology。setText(“电池技术:” + map。get(“技术”)); }@覆盖protected void onDestroy(){super。onDestroy();

华为手机电池寿命查询

thread。interrupt(); unregisterReceiver(接收者); }public String optionNum(双倍f){return df。format(f); }private void init(){/ **获取电池状态对象* /battery_Status =(TextView)findViewById(R。id。battery_status); / **获取电池运行状态* /battery_Run_Status =(TextView)findViewById(R。id。battery_health); / **获取电池电压* /battery_Voltage =(TextView)findViewById(R。id。battery_voltage); / **获取电池温度* /battery_Temperature =(TextView)findViewById(R。id。battery_temperature); / **获取电池技术* /battery_Technology =(TextView)findViewById(R。id。battery_technology); / **电池运行时间* / battery_Time =(TextView)findViewById(R。id。boot_time); / **获取电池电量对象* /battery_Level =(TextView)findViewById(R。id。battery); }Runnable runnable = new Runnable(){@ Overridepublic void run(){while(true){try {Thread。sleep(1000); long temp = SystemClock。elapsedRealtime(); 消息消息=新消息();android:textSize =“ 20sp” android:layout_marginBottom =“ 40dp” /》android:id =“ @ + id / battery_status” android:layout_width =“ match_parent” android:layout_height =“ wrap_content” /》android :id =“ @ + id / battery_health” android:layout_width =“ match_parent” android:layout_height =“ wrap_content” /》android:id =“ @ + id / battery_voltage” android:layout_width =“ match_parent” android :layout_height =“ wrap_content” /》android:id =“ @ + id /电池温度” android:layout_width =“ match_parent” android:layout_height =“ wrap_content” /》android:id =“ @ + id / battery_technology” android:layout_width =“ match_parent” android:layout_height =“ wrap_content” /》android:id =“ @ + id / battery” android:layout_width =“ match_parent” android:layout_height =“ wrap_content” /》android :id =“ @ + id / boot_time” android:layout_width =“ match_parent”

小米手机4636不显示电池

这是电源管理的简单实现。