Get temperature of battery on android

前端 未结 5 1920
再見小時候
再見小時候 2020-11-28 09:12

How do I get the temperature of the battery in android?

5条回答
  •  星月不相逢
    2020-11-28 09:30

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

提交回复
热议问题