2

I am testing out the BATTERY_PROPERTY_CURRENT_NOW function on two different devices.

Firstly I have a Samsung Galaxy S7 (Android 7.0 API 24) and a Nexus 6P (Android 8.1 API 27).

When I run BATTERY_PROPERTY_CURRENT_NOW on the Samsung I will get a result around -300, which seems about right to me. However on the Nexus I am getting anything from -120000 to 400000. Why would this be so off?

Here is the full code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final BatteryManager bm = (BatteryManager) getApplicationContext().getSystemService(Context.BATTERY_SERVICE);
    int current = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW);

    TextView textView = findViewById(R.id.textView);
    textView.setText(String.valueOf(current));

}

I'm not sure if it's because the Nexus is a more recent version of Android? But any suggestions would be welcome.

  • 1
    [The documented unit is microamperes](https://developer.android.com/reference/android/os/BatteryManager.html#BATTERY_PROPERTY_CURRENT_NOW), so -300 to me feels small for an active device. That's -0.3 milliamperes. The S7's battery is rated for 3000 milliampere-hours, so that would imply a 9000-hour runtime. I suspect many S7 owners would love that sort of performance. :-) Perhaps the unit of measure changed somewhere along the line. Or, perhaps Samsung is reporting milliamperes instead of microamperes. – CommonsWare Mar 23 '18 at 17:51
  • I think Samsung just doesn't support it. It is not even the correct milliseconds. I plotted graphs against current change on Vivo V9 and it shows that even in milliseconds the current changes a lot when a heavy app is running. This is not the case with Samsung. – M. Usman Khan May 10 '18 at 05:37

1 Answers1

0

I think Samsung phones return milliAmperes. Maximum current my phone can draw is 1.55 A. The function returns an integer between 1400 - 1450 which looks about right in milliAmperes. And it only updates that value once in 10 seconds.

Frank Shrestha
  • 103
  • 1
  • 6