當前位置:首頁 » 安卓系統 » android電壓

android電壓

發布時間: 2023-06-07 07:44:02

Ⅰ Android如何得到電量、溫度、電壓

package com.LB; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; import android.os.Bundle; import android.widget.TextView; public class Battery extends Activity { private int BatteryN; //目前電量 private int BatteryV; //電池電壓 private double BatteryT; //電池溫度 private String BatteryStatus; //電池狀態 private String BatteryTemp; //電池使用情況 public TextView TV; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 注冊一個系統 BroadcastReceiver,作為訪問電池計量之用這個不能直接在AndroidManifest.xml中注冊 registerReceiver(mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); TV = (TextView)findViewById(R.id.TV); } /* 創建廣播接收器 */ private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); /* * 如果捕捉到的action是ACTION_BATTERY_CHANGED, 就運行onBatteryInfoReceiver() */ if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { BatteryN = intent.getIntExtra("level", 0); //目前電量 BatteryV = intent.getIntExtra("voltage", 0); //電池電壓 BatteryT = intent.getIntExtra("temperature", 0); //電池溫度 switch

熱點內容
自己怎麼搭建網站伺服器 發布:2025-08-22 00:36:54 瀏覽:141
按鍵精靈只能做手游腳本嗎 發布:2025-08-22 00:31:22 瀏覽:152
php網站製作 發布:2025-08-22 00:31:19 瀏覽:488
java的http編程 發布:2025-08-21 23:56:32 瀏覽:988
大學資料庫試題 發布:2025-08-21 23:56:28 瀏覽:801
沾福卡的演算法 發布:2025-08-21 23:38:26 瀏覽:337
java極光 發布:2025-08-21 23:38:14 瀏覽:709
php路由框架 發布:2025-08-21 23:32:17 瀏覽:771
超微ipmi無法解析伺服器dns地址 發布:2025-08-21 23:31:14 瀏覽:162
私服魔域腳本 發布:2025-08-21 23:29:34 瀏覽:55