studio porcentaje poner mostrar como code bateria activar android sensor android-sensors temperature

porcentaje - Obtener la temperatura de la batería en Android



mostrar porcentaje de bateria android 7 (6)

Intenta leer el estático BatteryManager.EXTRA_TEMPERATURE

¿Cómo consigo la temperatura de la batería en Android?


Prueba esto:

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); } };

luego defina en sus declaraciones de variables:

private mBatInfoReceiver myBatInfoReceiver;

y en 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)); }

llamada posterior, por ejemplo, en un OnClickListener ()

float temp = myBatInfoReceiver.get_temp(); String message = "Current " + BatteryManager.EXTRA_TEMPERATURE + " = " + temp + Character.toString ((char) 176) + " C";


Puede obtener la temperatura de la CPU con esta función: obtenga la temperatura de la CPU desde un dispositivo Android utilizando el comando 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; } }

En mi gist para enviar solicitudes de extracción: https://gist.github.com/sajadabasi/7d76379e82d51efd0a24e5829c3ce572



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"; }


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)); }