The task is very common, but I can not find implementation on QT 5.x.
We need to know the current battery level of the smartphone / tablet on Android.
The task is very common, but I can not find implementation on QT 5.x.
We need to know the current battery level of the smartphone / tablet on Android.
Here's the usual java method, maybe it will help:
public float getBatteryLevel() { Intent batteryIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); if(level == -1 || scale == -1) { return 50.0f; } return ((float)level / (float)scale) * 100.0f; } Source: https://ru.stackoverflow.com/questions/382701/
All Articles