當前位置:首頁 » 安卓系統 » 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

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:645
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:936
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:632
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:821
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:731
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1066
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:299
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:160
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:852
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:763