Uzyskaj temperaturę baterii na Androidzie
Jak sprawdzić temperaturę baterii w Androidzie?
16
6 answers
Spróbuj tego:
private class mBatInfoReceiver extends BroadcastReceiver{
int temp = 0;
float get_temp(){
return (float)(temp / 10);
}
@Override
public void onReceive(Context arg0, Intent intent) {
temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0);
}
};
Następnie zdefiniuj w swojej zmiennej deklaracje:
private mBatInfoReceiver myBatInfoReceiver;
I in onCreate:
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
// ...
// Add this
myBatInfoReceiver = new mBatInfoReceiver();
this.registerReceiver(this.myBatInfoReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
Późniejsze wywołanie np. w onclicklistener ()
float temp = myBatInfoReceiver.get_temp();
String message = "Current " + BatteryManager.EXTRA_TEMPERATURE + " = " +
temp + Character.toString ((char) 176) + " C";
7
Author: Ingo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-09 15:18:37
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-09 15:18:37
Http://developer.android.com/reference/android/os/BatteryManager.html
Public static final String EXTRA_TEMPERATURE
Extra dla ACTION_BATTERY_CHANGED: integer zawierający aktualną temperaturę akumulatora.
14
Author: Select0r,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-10-22 13:40:55
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-10-22 13:40:55
public static String batteryTemperature(Context context)
{
Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
float temp = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0)) / 10;
return String.valueOf(temp) + "*C";
}
6
Author: XXX,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-08 23:40:25
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-08 23:40:25
TextView BatTemp;
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent intent)
{
// TODO Auto-generated method stub
int temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,0);
};
@Override
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.activity_main);
BatTemp = (TextView) this.findViewById(R.id.textView8);
this.registerReceiver(this.mBatInfoReceiver,new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
1
Author: Mohamad Bdour,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-15 19:58:40
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-15 19:58:40
Spróbuj odczytać statyczny int BatteryManager.EXTRA_TEMPERATURE
0
Author: GôTô,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-10-22 13:43:22
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-10-22 13:43:22
Możesz uzyskać temperaturę procesora za pomocą tej funkcji:
Pobierz temperaturę procesora z urządzenia z systemem android za pomocą polecenia sys/class/thermal/temp
.
public float getCpuTemp() {
Process process;
try {
process = Runtime.getRuntime().exec("cat sys/class/thermal/thermal_zone0/temp");
process.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = reader.readLine();
float temp = Float.parseFloat(line) / 1000.0f;
return temp;
} catch (Exception e) {
e.printStackTrace();
return 0.0f;
}
}
W moim gist, aby wysłać pull requests: https://gist.github.com/sajadabasi/7d76379e82d51efd0a24e5829c3ce572
0
Author: sajad abasi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-04 17:53:15
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-04 17:53:15