Getting the Battery Current Values for the Android Phone

Getting the battery current values for the Android Phone

After several experiments and help from various other groups, I found out that there is no way of getting Battery Current value through software only (as its not supported in h/w). Only way I found was to measure current flowing through battery by means of multimeter.

In Android, is there a way to get the battery current?

try this code,may be it would be help full for you:

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
//this will give you battery current status
int level = intent.getIntExtra("level", 0);

contentTxt.setText(String.valueOf(level) + "%");

int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
textView2.setText("status:"+status);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
textView3.setText("is Charging:"+isCharging);
int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
textView4.setText("is Charge plug:"+chargePlug);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;

boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
textView5.setText("USB Charging:"+usbCharge+" AC charging:"+acCharge);

}
};

in main class register this using:

 this.registerReceiver(this.mBatInfoReceiver, 
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

android - What's the unit of battery current value?

According to someone on a Google Groups forum, it is microamps (μA).

Android get battery current capacity in mA and total capacity of battery in mAh

Try this..

    public void getBatteryCapacity() {
Object mPowerProfile_ = null;

final String POWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile";

try {
mPowerProfile_ = Class.forName(POWER_PROFILE_CLASS)
.getConstructor(Context.class).newInstance(this);
} catch (Exception e) {
e.printStackTrace();
}

try {
double batteryCapacity = (Double) Class
.forName(POWER_PROFILE_CLASS)
.getMethod("getAveragePower", java.lang.String.class)
.invoke(mPowerProfile_, "battery.capacity");
Toast.makeText(MainActivity.this, batteryCapacity + " mah",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}

android: Get instant current from NON-supported devices

Most properties are read from kernel power_supply subsystem attributes of similar names. However, the exact properties, resolution of property values, and update frequency available for a specific device depend on:

Fuel gauge hardware, such as a Summit SMB347 or Maxim MAX17050.

Fuel gauge-to-system connection, such as the value of external current sense resistors.

Fuel gauge chip software configuration, such as values chosen for average current computation intervals in the kernel driver.

Official Documentation

Which means yes, it's a hardware/software limitation. It depends

How can I get the value of charging current (in mA) in an android application?

You can read the current on the battery using the BatteryManager class and then the BATTERY_PROPERTY_CURRENT_NOW property.

Decode battery values

use this for battery

switch (health) {
case BatteryManager.BATTERY_HEALTH_DEAD:

break;
case BatteryManager.BATTERY_HEALTH_GOOD:

break;
case BatteryManager.BATTERY_HEALTH_COLD:

break;
case BatteryManager.BATTERY_HEALTH_OVERHEAT:

break;
case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:

break;

default:
break;
}

use for pluged

switch (plugged ) {
case BatteryManager.BATTERY_PLUGGED_AC:

break;
case BatteryManager.BATTERY_PLUGGED_USB:

break;
case BatteryManager.BATTERY_PLUGGED_WIRELESS:

default:
break;
}

use for voltage

switch (voltage) {
case BatteryManager.BATTERY_STATUS_CHARGING:

break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:

break;
case BatteryManager.BATTERY_STATUS_FULL:
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
break;
case BatteryManager.BATTERY_STATUS_UNKNOWN:
break;
default:
break;
}


Related Topics



Leave a reply



Submit