Daito, at least somebody, has a sample code, how can the percentage of battery charge be obtained and inserted into the textview ...

Closed due to the fact that off-topic participants αλεχολυτ , Streletz , andreymal , Athari , Cheg 2 Oct '17 at 11:08 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The message contains only the text of the task, in which there is no description of the problem, or the question is purely formal (" how do I do this task ") . To reopen the question, add a description of the specific problem, explain what does not work, what you see the problem. " - Streletz, andreymal, Athari, Cheg
If the question can be reformulated according to the rules set out in the certificate , edit it .

1 answer 1

According to en-SO you should:

 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); // Error checking that probably isn't needed but I added just in case. if(level == -1 || scale == -1) { return 50.0f; } return ((float)level / (float)scale) * 100.0f; } 
  • Yuriy SPb, and how to bring the value in the textview? - Vadim
  • @ Vadim, textView.setText(text); - Yuriy SPb