Battery Voltage
//InCreate
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
getApplicationContext().registerReceiver(mBroadcastReceiver,iFilter);
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(), "Received", Toast.LENGTH_SHORT).show();
int voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE,0);
double volt = voltage * 0.0
java.text.DecimalFormat newFormat = new java.text.DecimalFormat("#.#");
double oneDecimalVolt = Double.valueOf(newFormat.format(volt));
textview1.setText("Battery Voltage");
textview1.setText(textview1.getText() +"
Millivolts : " + voltage);
textview1.setText(textview1.getText() + "
Volt : " + oneDecimalVolt);
}
};
Comments