I purchased Lenovo K8 note mobile which has stock android Nougat 7.1.1 . i am trying to display the battery percentage instead of graphical display on the top notification bar. I found no setting to do the same. Please help.
Asked
Active
Viewed 927 times
-4
-
2I think you might have better luck at https://android.stackexchange.com – Orkun Kocyigit Aug 21 '17 at 07:53
-
1Welcome to SO. This site is for **programming** questions only. – Phantômaxx Aug 21 '17 at 08:06
1 Answers
1
Use below code for getting battery percentage;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent intent) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
int voltage = intent.getIntExtra("voltage", 0);
int temperature = intent.getIntExtra("temperature", 0);
// batteryLevel.setText("Battery Status: " + String.valueOf(level) + "%");
// voltageLevel.setText("Battery Voltage: " + String.valueOf(voltage));
double temps = (double)temperature / 10;
// temperatureLevel.setText("Battery Temperature: " + String.valueOf(temps));
Toast.makeText(getApplicationContext(),String.valueOf(level),Toast.LENGTH_SHORT).show();
}
};
}

Vishal Vaishnav
- 3,346
- 3
- 26
- 57