How to find out the percentage of battery charge in Android? Here is the code I used:
registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Info.this.batteryLevel = intent.getIntExtra("level", -1); } }, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); as a result of which the value of the variable batteryLevel is 1134231552. Instead of "level" I tried to specify BatteryManager.EXTRA_LEVEL - the result is the same, each time there are such strange large numbers. How to fix the error?
I also tried to get the battery charge value like this:
Info.this.batteryLevel = (float) intent.getIntExtra("level", -1) / (float) intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); the result is the same.